programmatically put the calling servlet into the action of an HTML Form
in a controller servlet I have the doGet as
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
RequestDispatcher view = req.getRequestDispatcher("views/insert_item.jsp");
view.forward(req, res);
}
in the view insert_item.jsp
I want to post
back to the same calling servlet but in the HTML Form of the insert_item.jsp I want to specify the Action programmatically such as
<form method="post" action="<%= request.GET_CALLING_SERVLET%>">
I've tried
<form method="post" action="<%= request.getServletPath() %>">
<form method="post" action="<%=request.getRequestURI %>">
but these just put the path to the view views/insert_开发者_如何学Goitem.jsp
Is it possible to programmatically put the calling servlet into the action of an HTML Form?? Or am I once again trying some unorthodix approach?
You can always pass the original request in an attribute.
But a simpler way would be to use an empty action attribute (html).
<form method="post" action="">
精彩评论