• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsp forward tag

 
Nitin Singla
Greenhorn
Posts: 15
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you declaring the String in a Java snippet or Javascript?

WP
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using below
<%

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

%>
<jsp:forward page= <%=chgLocURL%> />
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once again: you cannot forward to a resource outside of the current web app.

You'll need to redirect.
 
Nitin Singla
Greenhorn
Posts: 15
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its giving page not found error.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They do completely different things and are not interchangeable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic