Forums Register Login

transfer from jsp to servlet

+Pie Number of slices to send: Send
I need help.

I transfer parameter from jsp to servlet and the opposite.

first I transfet the parameter from servlet to jsp by the code :request.setAttribute("KEY",i2);
and it works.

now I want new servlet to read the parameter from the jsp that I send the parameter from the former servlet .I try two ways
1-
String pss=(String) request.getParameter("i2");
2-String pss=(String) request.getParameter("KEY");

but the parameter did not transfer to the new servlet
What Is the problem?
+Pie Number of slices to send: Send
How are you passing control from the JSP to the servlet?

Recall that a request object only lives for the duration of a single request.

Bill
+Pie Number of slices to send: Send
How about using <jsp:incluede....> ? It also supports dynamic resources like servlets. BTW, by specifying <jsp:param> inside <jsp:include> you can pass your parameters to servlet.
Read the JSP Syntax reference for more details on this topic.
+Pie Number of slices to send: Send
request.getParameter() is used to read the inpts from form fields in the HTML (there's no JSP on the browser, the JSP generates HTML to send to the browser).

It is not used to read scoped variables created with setAttribute(). Why did you think it would?

Any scoped variables you create on the request go out of scope when the response is sent to the browser.

Perhaps this article will help with basic JSP concepts.
+Pie Number of slices to send: Send
if I will use COOKIE OR SESSION instead it can help?
+Pie Number of slices to send: Send
I've got a better idea. Instead of proposing knee-jerk solutions, why not explain why you are trying to do this and perhaps we can suggest the best means?
+Pie Number of slices to send: Send
 

alona ariel wrote:
request.setAttribute("KEY",i2);



from your description I presume that you want to keep the parameter in the session. change your code as followes
in first servlet
request.setattribute("Key",i2);
and in other servlet
request.getAttribute("Key");
+Pie Number of slices to send: Send
That also will not work.
+Pie Number of slices to send: Send
As an answer to Bear I will try to explain my programm
a person give his name and password if it true he enter to the bank.
but my problem is how the programm will remember is detail, si it gives him his own account.
My progrann check the name and password well, but can not remember the detail
+Pie Number of slices to send: Send
That's what the session is for.
The fastest and most reliable components of any system are those that are not there. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2573 times.
Similar Threads
Not get the session value
TypeCast from String to HashMap
Include JSP resource from JAR file?
POST request and reading data two time
Internationalization of string
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:51:59.