0

我正在使用一些 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”?

4

1 回答 1

2

将 action 属性添加到表单元素以指向正确的路径。

<form action="<c:url value="/MyServletPath/Page"/>" method="post">
于 2013-02-20T00:18:16.883 回答