I'm retrieving values from database to table in jsp.(to a column)
I want to insert that value into another table in database. To do that I'm using another jsp table to insert that value in db and I call that jsp page in my previous jsp's page form action tab.
I use request.getParameter()
method to get the values in my first jsp page to new jsp page, but I couldn't get the values using request.getParameter()
.
How can I solve this?
When opening the 2nd JSP you have to pass the relevant parameters (an ID I suppose) as GET parameters to the second page. That is, the link in your table should look like:
Then you can read that parameter with
request.getParameter("itemId")
on the second page.(if not using JSTL and EL, the
${..}
is replaced by<%= .. %>
)You should construct your url with the url tag:
This will give you URL-rewriting (append jsessionid when necessary) and URL-encoding of your params for free.
A solution that doesn't use JSTL or EL should be considered a special case.
You just need to pass the values as request parameters to the next request. This way they'll be available in the next request as, well, request parameters.
If the request from page A to page B happens to be invoked by a link, then you need to define the parameters in the URL:
This way they'll be as expected available by
request.getParameter()
inupdate.jsp
.If the request from page A to page B happens to be invoked by a
POST
form, then you need to define the parameters as input fields of the form. If you want to hide them from the view, then just use<input type="hidden">
.This way they'll be as expected available by
request.getParameter()
inupdate.jsp
.If you are still having trouble passing values with your form and request.getParameter() there is another method you can try.
In your code set each value pair to a session variable.
These values will now be available from any jsp as long as your session is still active.
Use:
to retrieve your values on the update.jsp page. Remember to remove any session variables when they are no longer in use as they will sit in memory for the duration of the users session.