I know how to pass parameters as a mydomain.com?id=2
request, however instead of the ?id=2
approach I'd like to implement a forward slash based approach to passing parameters in JSP Servlets?
Similar to Stackoverflow:
stackoverflow.com/questions/20425024533/question-title-goes-here
This what I currently have:
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>
Taking Stackoverflow format as the example, can you show me how I could pass a value (id) in the format of mydomain.com/questions/id_goes_here/post_title_goes_here
.
Thanks guys!