Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to keep values from calling multiple jsp

 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a question. I have one jsp (a.jsp) calling (b.jsp). Once a calls b it passes most of the information. Once I have b and all the values are filled out and I want to call c.jsp how do I keep the values from a in b and be able to insert c values.

One issue is that a value in b.jsp name is being set from a variable from a.jsp. When I call c.jsp and I pass a value back how do I set b.jsp name value from what I passed from c.jsp and not have the one from a.jsp.

Thank you,
Randy
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to be a bit more precise in your terminology.

JSPs don't "call" each other. The can include each other, redirect to each other, forward to each other, or submit to each other. Which of these do you mean by "call"?

Also, what is "pass data"? Scoped variables on the session? Request parameters from a query string or form elements?
 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All items being sent from jsp to jsp are scoped.

Form b submits to form c. When it is submitted it transfers a value from b to c. From the info i get from b i set up a list of options with radio buttons in c. Once the option is selected and they select the finished button it sumbits back to b and with it goes a different value that I need to set.

From a to b I am not sure. All I know is that it sets all the variables once it is called. It will not go back to a though.

Should i be using the redirect or forward instead of submitting?


Thank you,
Randy
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a servlet as your controller and submit all of your (forms/jsp's) to this servlet. That way when the request transfers from a.jsp it is forwared to the servlet where you can get the values using request.getParameter() and so on for b.jsp and c.jsp etc.

Its a good idea to have some sort of contoller when you are using multiple jsp pages and forwarding requests between them.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Randy Tatham:
All items being sent from jsp to jsp are scoped.


Where? Session? Request?


Form b submits to form c
.

I assume you mean to page c which contains a form?


When it is submitted it transfers a value from b to c.


How?

Once the option is selected and they select the finished button it sumbits back to b and with it goes a different value that I need to set.


Don't know what you mean by the part that I put in bold.

Should i be using the redirect or forward instead of submitting?


Probably not. Redirects and forwards are only used for immediate transfer from one resource to another.
 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is what I think i am goign to do. I am going to pass the other 5 values to c.jsp. when I sumbit to b.jsp again I will pass the 5 back and change 1 of them b4 that.

Although I feel that it is probably not the most efficient way of doing this.

Bear i am sorry i am still pretty new to this. Everything is being sumbitted by a form method="POST" action="" name="example". when they select the radio button i and selected finished (input button) it is being sumbited back via a javascript function that calls my b.jsp
 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you do this servlet? I am confused by you sumbitting the jsp to it. Do you just submit the data from the jsp? I know your explination is probably very simple to you but i am lost lol.

Thank you,
Randy
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This "/SomeURL" is an 'abstracted path name' for your servlet. Map this "SomeURL" to an actual servlet in the web.xml like this (Of course this assuming you are using tomcat servlet container)

<servlet>
<servlet-name>SomeServlet</servlet-name>
<servlet-class>com.somepackage.ActualServlet</servlet-class>
(this is the fully qualified path of the servlet)
</servlet>

Map the above servlet name to a URL using a mapping like this :

<servlet-mapping>
<servlet-name>SomeServlet</servlet-name>
<url-pattern>/SomeURL</url-pattern>
</servlet-mapping>


All this assuming you have basic knowledge about servlets and Tomcat container.

Once you are in the servlet you can forward the request to any other resource you want to.

Good luck!
[ June 14, 2006: Message edited by: vishwanath nadimpally ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic