我正在使用一些 JSP 页面和一个 servlet。
小服务程序 doPost():
String userPath = request.getServletPath();
if (userPath.equals("/PageAdm")) {
String username = request.getParameter("username");
String password = request.getParameter("password");
User userone = new User(username, password);
request.setAttribute("user", user);
RequestDispatcher view = request.getRequestDispatcher("view/Page.jsp");
view.forward(request, response);
} else if (userPath.equals("/Page")) {
String username = request.getParameter("username");
UsersService us = new UsersService();
User user = us.getUserByUsername(username);
request.setAttribute("user", user);
RequestDispatcher view = request.getRequestDispatcher("view/UserNameEdit.jsp");
view.forward(request, response);
}
当我登录时,我可以更改用户名,但是当我提交表单(单击)来更改它时,servletpath 仍然是“/PageAdm”,但它必须是“/Page”,所以我可以更改我的用户名。如何更改 servletpath,使其转到“/UserNameEdit”?