tags:

views:

29

answers:

1

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_item.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?

A: 

You can always pass the the original request in an attribute.

But a simpler way would be to use an empty action attribute (html).

<form method="post" action="">
h3xStream
I had tried that but it didn't work. But now I realize why. I was calling the servlet as http://localhost:8080/TestServlet2?method=new. When I hovered over the submit button, it was keeping the url parameters of "new" and that was overriding my hidden form paramter that set method=sqlInsert
jeff