有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用HttpServletRequest getPathInfo()和<a href=”“>

在我的JavaWeb应用程序中,我使用HttpServletRequest{}方法获取请求发送到Servlet的路径

我的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模式映射到链接到Controllerservlet。因此,每当找到/do路径时,请求就会被发送到控制器,控制器决定去哪里(如processRequest方法所示)

现在我遇到的问题是,当我尝试以相同的方式在HTML a标记中链接到控制器时,它不起作用,例如:

<a href="http://localhost:8080/do/viewDetails">View all details</a>

有没有一种方法可以让我对a href执行与对<form action...相同的操作

编辑:

单击“查看所有详细信息”链接时浏览器的屏幕截图:

enter image description here


共 (0) 个答案