Forward problem (JSP)

R

Raj_genius

This is a peculiar problem..plzz i need its solution as soon as
possible..here is my case:

I hav a jsp page where in i have 3 combo boxes, and corresponding 3
buttons..upon clicking each button, a javascript function is called
which checks if the corresponding selected option in the combo box is
valid or not..
If valid, it forwards the end user to another page for next phase of
actions..
now..what my problem is, after checking/validation thru the javascript
function, the function has to forward/move to either of 3 different
pages..i.e
if user clicks on button 1 and data of combo box 1 is valid then go to
page1.jsp
if user clicks on button 2 and data of combo box 2 is valid then go to
page2.jsp
if user clicks on button 3 and data of combo box 3 is valid then go to
page3.jsp

so..depending on whc button is clicked, the page can be forwarded to
any of the 3 pages..
i hav accomplished this by using location.herf within the javascript
function and i can go to the desired page
but the problem is that, the called jsp page(page1.jsp or page2.jsp or
page3.jsp) cannot access the calling page's controls using
request.getParameter(<parameter name>)

the called jsp page can access the caller page's controls only if i use
the submit() method in the calling page, which is not possible in my
case as i donot hav a single/unique page to submit..i hav 3 different
pages whc can be called..
if i use location.herf, then the required page is loaded, but the
called jsp page cannot access parameters using request.getparameter()
if i use jsp:forward tag, the page is forwarded immediately when its
loaded, without any action...

plzz tell me a solution to this problem so that i can forward to a new
page as well as access the caller's controls from the called jsp page...
 
M

Manish Pandit

Assuming the data being submitted is not multipart, why dont you append
the values to the location.href variable in a querystring format?

Pretty much like var newLocation =
'/somejsp.jsp?'+'param1='+param1+'&param2='+param2...

-cheers,
Manish
 
R

Raj_genius

tht wud b nice..but how to retrieve that data in the called page

can u show in code..

thanx 4 the reply
 
M

Manish Pandit

Raj_genius said:
tht wud b nice..but how to retrieve that data in the called page

can u show in code..

thanx 4 the reply


From your question it appears that you need to brush up on your JSP
syntax in general - google around and there is plenty of information
available.

Ideally, the routing of requests should be handled via a controller,
and not the JSP.

Hope this helps!

-cheers,
Manish
 
R

Raj_genius

thanx a lot...
temporarity..my problem is solved...but wht if i dont want the
parameter value to be displayed in the url..
in this case .. i cannot use xyz.jsp?param=''

is thr any other way ??so tht my parameter values can be hidden??
 
L

Lew

Raj_genius said:
thanx a lot...
temporarity..my problem is solved...but wht if i dont want the
parameter value to be displayed in the url..
in this case .. i cannot use xyz.jsp?param=''

is thr any other way ??so tht my parameter values can be hidden??

Set up the choice as one of several different HTML controls, e.g., submit
buttons. Use a <form> tag, naturally, with method set to "post".

<form name="x" method="post" action="/home">
...
<input type="submit" name="destiny" value="Go to A" />
<input type="submit" name="destiny" value="Go to B" />
</form>

and map the "/home" target to a controller servlet that decides where to forward:

public class Control extends HttpServlet
{
protected void doPost(
HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
String target;
String destiny = request.getParameter( "destiny" );
if ( destiny.equalsIgnoreCase( "go to a" ))
{
target = "A.jsp";
}
....
RequestDispatcher rd = request.getRequestDispatcher( target );
rd.forward( request, response );
}
}

Exceptions and package imports omitted for brevity.

- Lew
 
L

Lew

Set up the choice as one of several different HTML controls, e.g.,
submit buttons. Use a <form> tag, naturally, with method set to "post".

<form name="x" method="post" action="/home">
...

The action target should be "home", without the leading slash.

- Lew
 
R

Raj_genius

Thak you lew...thts an interesting and gr8 solution, thanks...
but here also i hav to use another new servlet/page do decide whc page
to forward..
but anyways..i guess i hav to pay sum price to get my work done..lol..
thanks evry1 for replying

- Raj
 
L

Lew

Raj_genius said:
Thak you lew...

Please post your replies in line with the quoted text, not on top of the
message. The latter is called "top-posting" and makes messages harder to follow.

- Lew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top