• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 863
  • Last Modified:

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
0
smanders
Asked:
smanders
  • 5
  • 5
1 Solution
 
kennethxuCommented:
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.
0
 
kennethxuCommented:
also, it is recommended that always return after sendRedirect. e.g.:

response.sendRedirect(request.getParameter("paper"));
return;
0
 
smandersAuthor Commented:
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?  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kennethxuCommented:
this error message should only occur when you use <jsp:forward>, because sendRedirect never uses RequestDispatcher. can you post your check_login.jsp?
0
 
smandersAuthor Commented:
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.
0
 
kennethxuCommented:
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.
0
 
smandersAuthor Commented:
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?
 
0
 
kennethxuCommented:
blame it on Gates :)


another thing you can try to let get_paper.jsp return a page contains javascript instead of redirect to the download file. something like:

please wait while your file is being downloaded
<script>
window.open( '<%=userBean.getPaperName()%>' );
</script>
0
 
smandersAuthor Commented:
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?
 
0
 
smandersAuthor Commented:
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.

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now