Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp newbie having problem with response.sendRedirect

 
Keav Julian
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am running into a bit of a problem with a simple task. I have a login page that redirects the user if they are not authenticated. The login page uses struts. I tried to use response.sendRedirect("url.jsp") when user is not authenticated but I get a blank page. Its like its stuck in the logon.do page and not going to url.jsp page. So I thought, maybe go the strut route. I added following definition to my tld file and tried to use <html:redirect href='<%=url%>'/> and I get the same result:
<tag>
<name>redirect</name>
<tagclass>org.apache.struts.taglib.RedirectTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>pageContext</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>parent</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>href</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

Does anyone have any suggestions? Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Keav",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Keav Julian
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gotcha. It's updated now.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you hand-enter the same URL directly into the browser? Does the expected page appear?
 
Keav Julian
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I even added a return statement after the sendRedirect call. Also, I tried using

response.sendRedirect(response.encodeRedirectUrl("url.jsp"));

As well as I tried to put in a url that everyone can get to like http://wwww.yahoo.com

I get the same thing. A blank page. No error messages. None in any log files that I have found either.
 
Keav Julian
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I am trying a different approach. But atleast I am getting an error message this time with my different approach.
I changed the sendRedirect and used this instead:
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(noCookieURL.trim());
dispatcher.forward(request,response);

org.apache.jasper.JasperException: Path https://webtest.com/empsvcs/hrpinmgt/pagLogin/?retURL=http%3A%2F%2Fatomiis2-dev.com%3A8080%2Fbusinessobjects%2Fenterprise115%2Fdesktoplaunch%2FInfoView%2Flogon%2Flogon.do&sysName=ATOM does not start with a "/" character
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.crystaldecisions.ePortfolio.framework.common.AutoWrapExceptionAction.process(AutoWrapExceptionAction.java:83)
com.crystaldecisions.webapp.struts.framework.AbstractEnterpriseAction.perform(AbstractEnterpriseAction.java:38)
org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1787)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1586)
com.crystaldecisions.webapp.struts.framework.CrystalUTF8InputActionServlet.process(CrystalUTF8InputActionServlet.java:29)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Switching between a redirect and a forward because you can't get one or the other to work isn't a great idea.

Which one do you want to use? That's the one to get working.
 
Keav Julian
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would prefer to get the sendRedirect working but was looking for a plan B in case I can't get it to work.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it works from the browser it means the page is OK. It's likely the URL that you are supplying to the redirect that's the issue.

So, what is it? And what's the browser URL that did work?
 
Keav Julian
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesnt matter what url I redirect the user to even a known url (i.e. http://www.yahoo.com) it still doesnt work.

The user comes into the following url:
https://atom.myhost.com:8080/businessobjects/enterprise115/desktoplaunch/InfoView/logon/logon.do

I have the following declared:

String encReturnURL = URLEncoder.encode("https://atom.myhost.com:8080/businessobjects/enterprise115/desktoplaunch/InfoView/logon/logon.do");
string noCookieURL="https://webtest.myhost.com/empsvcs/hrpinmgt/pagLogin/?retURL=" + encRetURL+ "&sysName=ATOM";

then I do a cookie check
If no cookie found I do:
response.sendRedirect(noCookieURL.trim());
return;


The resulting redirect url comes out to be:
https://webtest.myhost.com/empsvcs/hrpinmgt/pagLogin/?retURL=http%3A%2F%2Fatom.myhost.com%3A8080%2Fbusinessobjects%2Fenterprise115%2Fdesktoplaunch%2FInfoView%2Flogon%2Flogon.do&sysName=ATOM
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic