gpt4 book ai didi

java - 如何更改 HttpServletRequest.servletpath?

转载 作者:行者123 更新时间:2023-12-02 07:15:34 32 4
gpt4 key购买 nike

我正在使用一些 JSP 页面和一个 servlet。

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”?

最佳答案

向表单元素添加一个操作属性以指向正确的路径。

<form action="<c:url value="/MyServletPath/Page"/>" method="post">

关于java - 如何更改 HttpServletRequest.servletpath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14970014/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com