aspose file tools*
The moose likes JSP and the fly likes How to redirect to another page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to redirect to another page" Watch "How to redirect to another page" New topic
Author

How to redirect to another page

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
I have two questions? How can I redirect to another page through a conditional and from a button press. I cannot figure this out, if you know how please let me know. Thanks.

Psedou code is below.

---------first -----------
<%
if(x == 1)
go to www.first.html

else
go to www.second.jsp

%>
-------second----------if this button is press I want to redirect to a different page

<input type="submit" name="Submit3" value="Delete Record" redirect to www.third.jsp >
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61191
    
  66

How can I redirect to another page through a conditional and from a button press.


You don't. A redirect is a server-side activity. A button press is a client-side activity. To move to another page as a result of a button press you would use the normal client-side mechanisms: submit a form, load a new page under javascript control, and so on.

if this button is press I want to redirect to a different page

<input type="submit" name="Submit3" value="Delete Record" redirect to www.third.jsp >


Again, a pure HTML/Javascript issue. Simply place the button in a form whose action specifies the page to which you want to submit.
[ September 19, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61191
    
  66

Posted by Fritz in another (now closed) topic:

posted September 19, 2005 02:50 PM Profile for Fritz Largosa Email Fritz Largosa Send New Private Message Edit/Delete Post What is the command to allow me to load another page? Below is the sample code of what I want to do. Thanks.

<%
if( x = 1)
%>
go to www.one.html // I do not know this command in javascript.

<%else%>
to to www.two.jsp
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61191
    
  66

So I assume from this that you have a server-side variable named x that will determine where a button will send the page to?

I'm also assuming that you in a pre-JSP 2.0 environment using scriptlets rather than the JSTL. If so, I'd code it something along the lines of:



under JSP 2.0:



[ September 19, 2005: Message edited by: Bear Bibeault ]
[ September 19, 2005: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61191
    
  66

P.S. If the URL to be generated needed params or was internal to the web app, I'd opt for the <c:url> tag over the simple <c:set> shown above.
Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to redirect to another page