我知道如何将参数作为mydomain.com?id=2
请求传递,但不是?id=2
方法,而是希望实现基于正斜杠的传递方法JSP Servlets中的参数?
与Stackoverflow类似:
stackoverflow.com/questions/20425024533/question-title-goes-here
这就是我目前所拥有的:
JSP Page 1
<html>
<head>
</head>
<body>
<!--Other Page HTML-->
<a href="PostServlet">Click here to view Post</a>
</body>
</html>
PostServlet
public class PostServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String post_id = request.getParameter("id");
RequestDispatcher rd = getServletContext().getRequestDispatcher("/BlogPost.jsp");
rd.forward(request, response);
}
}
的web.xml
<servlet>
<servlet-name>PostServlet</servlet-name>
<servlet-class>com.myweb.web.servlet.PostServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PostServlet</servlet-name>
<url-pattern>/PostServlet</url-pattern>
</servlet-mapping>
以Stackoverflow格式为例,您能告诉我如何以mydomain.com/questions/id_goes_here/post_title_goes_here
的格式传递值(id)。
谢谢你们!