• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to retrive servlet data in jsp page

 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried to retrive a value passed by the request dispatcher method in "login servlet " but unable to get it in "login.jsp"


login servlet:



login.jsp


does requestdispatcher pass the variables in login servlet.if it passes then why i am not getting the value or does
it require to pass value explicitely..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tushar panda wrote:a value passed by the request dispatcher method in "login servlet "

Where? There is nothing in your servlet code to pass the value to the JSP.

Use the following:


Then in the JSP:


 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in line 2 in login servlet i have mentioned in comment that the address1 is the target page(which i have set before as login.jsp) and in
line 1 i am getting the desired value of "msg" variable . which means when line 3 is executed requestdispatcher must pass it to login.jsp . and in login.jsp in line 3 i must get the value because i retrieved it in line 2 .
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea what you are trying to say.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've retrieved the value (a parameter) but never set it as an attribute--so it won't be available on the JSP. Did you try what Bear suggested?
 
Led Estonilo
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this




then

 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a few things missing from your servlet code which makes it difficult to predict what's going wrong.



How did you retrieve msg?? Is it retrieved as request.getParameter("msg")?? Secondly, what's the value of address1?? Have you overwritten the msg request parameter like Request parameters are passed as is when you use request dispatcher (unless you override them as the example that I gave).

Led did you try your program?? You are setting a request attribute and extracting a request parameter in the JSP. That will not work. Using scriptlets in JSP is also not a very good idea. The solution that Bear gave is the easiest way of achieving the result...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic