我知道如何将参数作为mydomain.com?id=2
请求传递,但是?id=2
我想实现基于正斜杠的方法来在 JSP Servlets 中传递参数,而不是这种方法?
类似于 Stackoverflow:
stackoverflow.com/questions/20425024533/question-title-goes-here
这是我目前拥有的:
JSP 第 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
.
多谢你们!