?
Solved

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

Posted on 2003-03-17
10
Medium Priority
?
789 Views
Last Modified: 2010-04-01
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
Comment
Question by:smanders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 8155983
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8156103
also, it is recommended that always return after sendRedirect. e.g.:

response.sendRedirect(request.getParameter("paper"));
return;
0
 

Author Comment

by:smanders
ID: 8156253
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:kennethxu
ID: 8156554
this error message should only occur when you use <jsp:forward>, because sendRedirect never uses RequestDispatcher. can you post your check_login.jsp?
0
 

Author Comment

by:smanders
ID: 8158626
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8159554
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
 

Author Comment

by:smanders
ID: 8163521
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
 
LVL 14

Accepted Solution

by:
kennethxu earned 440 total points
ID: 8163641
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
 

Author Comment

by:smanders
ID: 8163738
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
 

Author Comment

by:smanders
ID: 8163764
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New style of hardware planning for Microsoft Exchange server.
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question