Link to home
Start Free TrialLog in
Avatar of smanders
smanders

asked on

Opening a PDF File with jsp:forward or response.sendRedirect

I am very new to JSP and Java so the solution may be simple. ButI have been struggling with this for many many hours.  Here it is:

I am building a white paper registration form.  When the user clicks a link for one of the papers, I  pass the paper name as a parameter to a get_paper.jsp page (i.e., ?paper=whitepaper.pdf or ?paper=whitepaper.zip).  get_paper.jsp does the following:
   -------
<jsp:useBean id="userBean" scope="session" class="webregistration.UserBean" />
<jsp:setProperty name="userBean" property="paperName" param="paper"/>
<%
       if (userBean.isUserRegistered()) {
         response.sendRedirect(request.getParameter("paper"));
       } else {
         response.sendRedirect("papers_login.jsp");
       }
%>

 --------

 This logic opens the paper correctly as long as the user is registered using the request.getParameter.

However, here is my problem.  If the user is not logged on, they are directed to  the papers_login page where they must enter their username and password in a form.  The action on this form is check_login.jsp that validates the username and password.  If valid, I must open the paper otherwise redirect back to login page.

The paper does not open correctly in check_login however.  If I use a - <jsp:forward page="<%= userBean.getPaperName() %>" /> - I get a "no way to service request for /solutions/papers/cse_unifed_change.zip" error.

If I use a - response.sendRedirect(userBean.getPaperName()); - The paper gets passed to the window and displays in the address bar but it will not open unless I hit enter to submit the address bar value again.

I  hope this makes sense. Thanks
Avatar of kennethxu
kennethxu

you cannot use <jsp:forward> to a zip file. but the response.redirect should work.
you can try redirect to "get_paper.jsp?paper=" + userBean.getPaperName()
or try it on other browser to see if it is a browser bug.
also, it is recommended that always return after sendRedirect. e.g.:

response.sendRedirect(request.getParameter("paper"));
return;
Avatar of smanders

ASKER

I changed the code in check_login.jsp to :

response.sendRedirect(userBean.getPaperName());
return;

In both IE and Netscape, I get the following error in the iPlanet server error log:

[17/Mar/2003:21:30:43] config (  640): for host 206.138.153.73 trying to POST /solutions/papers/cse_design_03142002.pdf, internal-redirect reports: no way to service request for /solutions/papers/cse_design_03142002.pdf

[17/Mar/2003:21:30:43] warning (  640): RequestDispatcher: forward call failed


Any other ideas?  
this error message should only occur when you use <jsp:forward>, because sendRedirect never uses RequestDispatcher. can you post your check_login.jsp?
You are correct! I forgot to post the new page.  That is what happens when you stare at the same thing for 10 hours straight.

Your idea got me much closer. Everything works correctly in Netscape now.  In IE, an attempt is made to open the correct pdf document but there is an error - "error opening document" in the browser. If I hit enter, to resubmit the address, it opens correctly.
Will you try to test it on another PC? IE has a lot of bugs related to such thing. I experience that IE6 suddenly refuse to work on some site, only a complete re-install solved the problem.
Ok, here is the scoop.  It works fine with Netscape on all machines I tested.  IE has 3 different results on 3 different machines.  

Machine 1 - "Error opening document" error in browser. File doesn't open correctly until I hit enter to resubmit the address.

Machine 2 - Opens fine

Machine 3 - Server error - "You are not authorized to view this page".  

Each machine consistently returned the same results.  If you have any other ideas that would be great, otherwise, I guess I should close this question since my original question was answered.  I cannot believe I would get such different results in browsers.  How in the world does one debug this type of thing?
 
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, here is the scoop.  It works fine with Netscape on all machines I tested.  IE has 3 different results on 3 different machines.  

Machine 1 - "Error opening document" error in browser. File doesn't open correctly until I hit enter to resubmit the address.

Machine 2 - Opens fine

Machine 3 - Server error - "You are not authorized to view this page".  

Each machine consistently returned the same results.  If you have any other ideas that would be great, otherwise, I guess I should close this question since my original question was answered.  I cannot believe I would get such different results in browsers.  How in the world does one debug this type of thing?
 
I have no idea why I sent the same comment twice.  Oh well. Ignore.

I will take your suggestion and try the window.open.  Hopefully that will make a difference.  Thanks so much for your help.