Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

Forward problem (JSP)

Thread view: 
Raj_genius - 08 Jan 2007 08:14 GMT
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...
Manish Pandit - 08 Jan 2007 11:53 GMT
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
Raj_genius - 08 Jan 2007 12:09 GMT
tht wud b nice..but how to retrieve that data in the called page

can u show in code..

thanx 4 the reply

> Assuming the data being submitted is not multipart, why dont you append
> the values to the location.href variable in a querystring format?
[quoted text clipped - 4 lines]
> -cheers,
> Manish
Manish Pandit - 08 Jan 2007 12:13 GMT
> tht wud b nice..but how to retrieve that data in the called page
>
> can u show in code..
>
> thanx 4 the reply

<% request.getParameter("param1"); %> in a scriptlet, or
${param.param1} in EL.

>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
Raj_genius - 08 Jan 2007 12:39 GMT
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??

> > tht wud b nice..but how to retrieve that data in the called page
> >
[quoted text clipped - 16 lines]
> -cheers,
> Manish
Lew - 09 Jan 2007 06:58 GMT
> 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
Lew - 10 Jan 2007 00:04 GMT
Raj_genius wrote:
>> 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">
>   ...

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

- Lew
Raj_genius - 12 Jan 2007 18:34 GMT
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
> Raj_genius wrote:
> >> is thr any other way ??so tht my parameter values can be hidden??
[quoted text clipped - 8 lines]
>
> - Lew
Lew - 13 Jan 2007 17:54 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.