permaculture playing cards*
The moose likes JSP and the fly likes Jsp forward tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp forward tag" Watch "Jsp forward tag" New topic
Author

Jsp forward tag

Nitin Singla
Greenhorn

Joined: Oct 05, 2011
Posts: 15

String chgLocURL ="https://google.com";

<jsp:forward page="${chgLocURL}" />


its not working . Can somebody help how can i use string with jsp forward tag in my jsp.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

Are you declaring the String in a Java snippet or Javascript?

WP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

If chgLocURL is a scripting variable, then it's not visible to the EL. You should never be mixing scriptlets in with the EL. In fact, you should never be using scriptlets at all.


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

Joined: Jan 10, 2002
Posts: 60782
    
  65

William P O'Sullivan wrote:Are you declaring the String in a Java snippet or Javascript?

As it's not valid JavaScript syntax, I think it's clear that it's a Java scriptlet.
Nitin Singla
Greenhorn

Joined: Oct 05, 2011
Posts: 15

i am using below
<%

String chgLocURL ="https://google.com";

%>
<jsp:forward page= <%=chgLocURL%> />
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

See my reply. Scriptlets are 10 years out of date. Read this JspFaq entry.

In any case, you cannot forward to a resource outside of the current web application.
Nitin Singla
Greenhorn

Joined: Oct 05, 2011
Posts: 15

Please help me out with this code fix:

my url is in strnig.
and i need to forward to this new url which is in my string, how should i forward. Please can somebody provide me with right code snippet?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Once again: you cannot forward to a resource outside of the current web app.

You'll need to redirect.
Nitin Singla
Greenhorn

Joined: Oct 05, 2011
Posts: 15

Sorry for the confusion. Actually the url is ini scope of my app only. google.com is just an example. Dont get confuse with this. Only thing i want to know if in anyway i can use this string so that i can forward to the url that is in the string.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Nitin Singla wrote:Sorry for the confusion. Actually the url is ini scope of my app only. google.com is just an example.

This is called a "red herring" and is to be avoided. Show us real data, or as real as possible, and you won't waste the time of the people trying to help you. Please read AvoidRedHerrings.

Dont get confuse with this

Too late.

Only thing i want to know if in anyway i can use this string so that i can forward to the url that is in the string.

When you show us the real code, and show us the real errors that are occurring maybe we can help you.
Nitin Singla
Greenhorn

Joined: Oct 05, 2011
Posts: 15

Hi .

Apologies for my previous reply.

Below is my code snippet:

<%
String chgLocURL ="/jsp/welcome.jsp";

%>
<jsp:forward page="{<%=chgLocURL %> }"/>


It is not working.
Please help me how can i use this string. I just need to forward to the path stored in string chgLocURL from my current jsp in my application.
Please help with the code snippet.
Once again apologies for my previous post.
Thanks.
Nitin Singla
Greenhorn

Joined: Oct 05, 2011
Posts: 15

Its giving page not found error.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Does the page exist? If so, where? Does it work when you hard-code the path into the directive? You're still very far from giving us complete information.
cle tan
Ranch Hand

Joined: Jun 11, 2012
Posts: 68
Alternatively you can try using


difference between forward and redirect

http://javapapers.com/jsp/difference-between-forward-and-sendredirect/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

They do completely different things and are not interchangeable.
 
 
subject: Jsp forward tag
 
Similar Threads
passing objects from one jsp to another !!
To call a servlet from a JSP
code help!!
Struts ForwardAction vs Forward tag in jsp
difference between response.sendRedirect and jsp forward tag