tags:

views:

1774

answers:

4

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 couldnt get that values using request.getParameter().

How can i solve this

+1  A: 

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:

<a href="edit.jsp?itemId=${item.id}" />

Then you can read that parameter with request.getParameter("itemId") on the second page.

(if not using JSTL and EL, the ${..} is replaced by <%= .. %>)

Bozho
A: 

This is my part of code.

user ID Field ID < <%=userid%> <%=fieldid%>

i want to get value of user id and field id to my update.jsp page. i use request.getParameter("userid") in update.jsp page i tried to pass this in my form action also.but cant get that in update.jsp

devuser
Please do not post comments, questions nor updates as **answers**. Post comments as comments, post questions as questions and post updates by editing the question.
BalusC
Thanks for your answer.It works successfully !!!
devuser
A: 

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:

<a href="update.jsp?userid=${user.id}&fieldid=${field.id}">update</a>

This way they'll be as expected available by request.getParameter() in update.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">.

<form method="update.jsp" action="post">
    ...
    <input type="hidden" name="userid" value="${user.id}">
    <input type="hidden" name="fieldid" value="${field.id}">
</form>

This way they'll be as expected available by request.getParameter() in update.jsp.

BalusC
A: 

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.

session.setAttribute("userId", userid);
session.setAttribute("fieldId", fieldid);

These values will now be available from any jsp as long as your session is still active.

Use:

int userid = session.getAttribute("userId");
int fieldid = session.getAttribute("fieldId");

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.

Gthompson83