• Post Reply Bookmark Topic Watch Topic
  • New Topic

transfer from jsp to servlet

 
alona ariel
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Andriy Pererva
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
alona ariel
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I will use COOKIE OR SESSION instead it can help?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That also will not work.
 
alona ariel
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what the session is for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!