java使用HttpServletRequest getPathInfo()和<a href=”“>
在我的JavaWeb应用程序中,我使用HttpServletRequest
{
我的Servlet:Controller
包含以下代码:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getPathInfo();
RequestDispatcher dispatcher = null;
if(action.equals("/viewDetails"))
{
dispatcher = this.getServletContext().getRequestDispatcher("/viewDetails.jspx");
}
}
在这里,我检查请求的操作是什么,以便我可以将用户引导到适当的视图
现在在我的loginForm.jspx
中,我有一个如下的登录表单:
<form method="POST" action="http://localhost:8080/do/viewDetails">
这将通过控制器识别的操作:/viewDetails
进入控制器
在我的网上。XMLI已将/do
模式映射到链接到Controller
servlet。因此,每当找到/do
路径时,请求就会被发送到控制器,控制器决定去哪里(如processRequest方法所示)
现在我遇到的问题是,当我尝试以相同的方式在HTML a
标记中链接到控制器时,它不起作用,例如:
<a href="http://localhost:8080/do/viewDetails">View all details</a>
有没有一种方法可以让我对a href
执行与对<form action...
相同的操作
编辑:
单击“查看所有详细信息”链接时浏览器的屏幕截图:
共 (0) 个答案