• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Pass parameters from one jsp page to other jsp page

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to pass a String from one jsp page(say A.jsp) to other(say B.jsp) without displaying the second page(B.jsp).
I have tried setAttribute and getAttribute but null value is received on the B.jsp. Please help
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JSP that doesn't display sounds like it would be better implemented as a servlet. I would have A.jsp submit the String as a request parameter, probably by posting it with a form directed to a URL handled by my B servlet. The B servlet would have a doPost() method, and could do whatever it wanted to do with the String.
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to explain why you are trying to do what you are trying to do. As Greg pointed out, what you are describing is not a good design. A JSP is an end point that should be rendering the view.
 
Ranch Hand
Posts: 33
Google Web Toolkit Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is some way to do this
1. Using Query parameter

Then you can read that parameter with

on the second page.

2. Using Hidden variable

3. Using Session object


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

 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ganesh shirsat
Thanks for the reply but i tried all three aproaches but i am getting out as null.what do i do?
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By "not displaying", do you mean you want to create a pop-under window or something similar?
Also we cannot help you out unless you TellTheDetails, or PostRealCode.
One possible reason could be incorrect variable name.
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So it doesn't matter to you that you're following poor practices?
 
Greenhorn
Posts: 12
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
request.setAttribute() and request.getAttribute() should solve your problem.

Pay heed to this as well:

So it doesn't matter to you that your following poor practices?

 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Bear Bibeault
I really appreciate the concern but the problem is i have been trying very hard to get the servlet running but its not working and the deadline for the project which i am preparing is just a few days away ,thats why i am trying to get the thing to work.I have definitely kept your advice in mind and will follow it after this project.
 
Greenhorn
Posts: 7
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manas, it will be better if you explain the exact scenario so that Javaranchers can help you.

Parameter set is retrieved as null, one of the reasons could be where you have set the parameter & how you are getting it. Have you included jsp page inside another one or you don't at all want that page to be displayed? If you don't want to display it then you should use servlet for that. If servlet is not working then there must be some mistake configuring servlet in deployment descriptor or calling properly mapped servlet.

It will all be anticipated answers. Please share more detail for perfect one.
 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK got the servlet working heres the scenario and the real problem

I am making a registration page which performs ajax validation on email to check its validity and availablility(from database). The form should not be submitted on click of submit button if email id is invalid Now the problem is that my ajax call is simply displaying valid email or invalid ,and i need it to return true or false so that i could pass this value to form in order to prevent its submission.
I am unable to return any value from servlet KEEPING IN MIND THAT MY PAGE SHOULDN'T REFRESH.(i used request dispatcher but it refreshes the page so setattribute and getattribute wont work here).
heres my jsp code(reginfo.jsp)



and heres my servlet (regajax4.java)
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've already asked your Ajax question at least 3 other times, and the answer to your Ajax problem is here. Please do not spread a question across multiple posts. It just wastes everyone's time.

Also, the above code is way too much to look through. Please post an SSCCE demonstrating the issue.
 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heres the shorted code.sry am new around here i am learning from my mistakes

heres my jsp code(reginfo.jsp)



and heres my servlet (regajax4.java)
 
Every plan is a little cooler if you have a blimp. And a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic