Alaska Cowboy
asked on
URL to open a Word document works on IE-7 but not on FF-4 or Chrome 10.0
I have a JSP page that has this link:
file:///R:/FTP/Highmark/da ta/test/od s_cdr_tab_ cnt_035_20 11_04_26_a t_10_33.do c
This is on a corporate intranet and everyone has access to this directory.
The file opens as expected in IE-7, but it won't open in FF-4 or Chrome 10.0. On FF and Chrome, it looks like a link but nothing happens when I click on it.
file:///R:/FTP/Highmark/da
This is on a corporate intranet and everyone has access to this directory.
The file opens as expected in IE-7, but it won't open in FF-4 or Chrome 10.0. On FF and Chrome, it looks like a link but nothing happens when I click on it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
rrz, ok, thank you, I will give it a try.
ASKER
rrz, it looks like you wrote what I need, but not sure how to wire everything.
I'm running Tomcat 5.5.
What you wrote looks like it might do the trick, but I have a few questions:
- where does this code go ?
- how is it called ? I would have to pass in "R:/FTP/Highmark/data/test /ods_cdr_t ab_cnt_035 _2011_04_2 6_at_10_33 .doc"
Thanks.
I'm running Tomcat 5.5.
What you wrote looks like it might do the trick, but I have a few questions:
- where does this code go ?
- how is it called ? I would have to pass in "R:/FTP/Highmark/data/test
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, I needed the web.xml info, thanks.
Still need to know where the code goes and how to pass the file name.
I will increase the points when I'm back on the computer, I don't think I can do it in mobile.
Still need to know where the code goes and how to pass the file name.
I will increase the points when I'm back on the computer, I don't think I can do it in mobile.
>Still need to know where the code goes
You have to compile the Servlet and put the class file into your web app's classes folder. For example
WEB-INF/classes/rrz/Downlo adServlet. class
>how to pass the file name.
For testing just use the JSP I posted.
Where is the file name coming from ? Are you going to have a list of them for the user to choose from ?
You have to compile the Servlet and put the class file into your web app's classes folder. For example
WEB-INF/classes/rrz/Downlo
>how to pass the file name.
For testing just use the JSP I posted.
Where is the file name coming from ? Are you going to have a list of them for the user to choose from ?
ASKER
Ok, thanks. The file name comes from Oracle.
I will get back to this Monday.
I will get back to this Monday.
ASKER
increasing points.
ASKER
rrz, in your servlet code, is this line needed -->String filename = "test.doc";
I'm assuming that's left over and now shouldn't be there.
I'm assuming that's left over and now shouldn't be there.
ASKER
where should I put the servlet ?
in my java components, I have
- dao
- domain
- web
I'm guessing web, but is there a standard place ?
in my java components, I have
- dao
- domain
- web
I'm guessing web, but is there a standard place ?
ASKER
well, it's set up but not working properly, I get this: "Error 404: SRVE0190E: File not found: /getDoc"
I removed the "test.doc" reference, and I double-verified the file actually exists and can be opened.
here's the link: http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
and this opens from FF
file:///R:/FTP/Highmark/da ta/test/od s_cdr_tab_ cnt_104_20 11_04_26_a t_17_02.do c
I removed the "test.doc" reference, and I double-verified the file actually exists and can be opened.
here's the link: http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
and this opens from FF
file:///R:/FTP/Highmark/da
/********* Call getDoc *********/
<c:otherwise><a href="getDoc?filename=<c:out value="${hist.cdrReportLoc}"/>"><c:out value="${hist.procDescription}"/></a></c:otherwise>
/******** Servlet, only thing I changed was removing "test.doc" ********/
package com.carefirst.edw.web;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DownloadServlet extends HttpServlet {
@Override
public void init(){
System.out.println("init of DownloadServlet");
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
InputStream in = null;
OutputStream out = null;
String fileName = request.getParameter("fileName");
if(fileName != null){
try {
File file = new File(fileName);
// String filename = "test.doc";
FileInputStream fis = new FileInputStream(file);
response.setContentType("application/msword");
out = new BufferedOutputStream(response.getOutputStream());
in = new BufferedInputStream(fis);
response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
int c;
while( ( c=in.read() ) != -1 ) out.write( c );
}
catch(FileNotFoundException fnfe){
response.sendError( HttpServletResponse.SC_NOT_FOUND);
}
finally {
if( in != null ) try { in.close(); } catch( Exception e ) {}
if( out != null ) try { out.close(); } catch( Exception e ) {}
}
} else response.sendError( HttpServletResponse.SC_BAD_REQUEST);
}
}
>in your servlet code, is this line needed -->String filename = "test.doc";
Yes, it is needed because that is the file name that is used in "Content-Disposition". It will appear in the dialog box that asks the user to open MS Word. You can name it anything you want to name it. You could also parse the file name from the url that came from the database and use that.
>where should I put the servlet ?
I don't know your development environment. Are you using a IDE ? Anyway the Servlet needs to be compiled and put into its package folder and that should placed into your web app's classes folder.
WEB-INF/classes/com/carefi rst/edw/we b/Download Servlet.cl ass
Or if it is being put into a jar that should be placed into your web app's lib folder.
>well, it's set up but not working properly,
Please post how you mapped the Servlet in your web app's web.xml file ?
>I get this: "Error 404: SRVE0190E: File not found: /getDoc"
This is telling us that the Servlet is not being found.
For testing, begin with a Simple Servlet. Try using the Servlet below here. Try browsing to
http://localhost:9080/edw/getDoc
or use
<a href="getDoc"></a>
in a JSP that is in your web app's root folder.
The init method was included for debugging. It can be removed later. But for now you should see the init message in your console when the Servlet is loaded.
Yes, it is needed because that is the file name that is used in "Content-Disposition". It will appear in the dialog box that asks the user to open MS Word. You can name it anything you want to name it. You could also parse the file name from the url that came from the database and use that.
>where should I put the servlet ?
I don't know your development environment. Are you using a IDE ? Anyway the Servlet needs to be compiled and put into its package folder and that should placed into your web app's classes folder.
WEB-INF/classes/com/carefi
Or if it is being put into a jar that should be placed into your web app's lib folder.
>well, it's set up but not working properly,
Please post how you mapped the Servlet in your web app's web.xml file ?
>I get this: "Error 404: SRVE0190E: File not found: /getDoc"
This is telling us that the Servlet is not being found.
For testing, begin with a Simple Servlet. Try using the Servlet below here. Try browsing to
http://localhost:9080/edw/getDoc
or use
<a href="getDoc"></a>
in a JSP that is in your web app's root folder.
The init method was included for debugging. It can be removed later. But for now you should see the init message in your console when the Servlet is loaded.
package com.carefirst.edw.web;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DownloadServlet extends HttpServlet {
@Override
public void init(){
System.out.println("init of DownloadServlet");
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/plain");
response.getWriter().write("This is a test!);
}
}
ASKER
oh, I'm pretty sure I didn't map this in the web.xml file.
so everything is looking good so far, hopefully this will fix it. Unfortunately, I won't be able to get to this until later today or possibly not until tomorrow.
so everything is looking good so far, hopefully this will fix it. Unfortunately, I won't be able to get to this until later today or possibly not until tomorrow.
You never told me which web server you are using. If you using Servlet 3.0 API then you could use annotations instead of mapping. If you using anything less than Servlet 3.0 then you will have to use mapping.
ASKER
I'm using Tomcat 5.5.
How would I know if I'm using Servlet 3.9 API or not ?
also, another question, what does this mean: "@Override" - - - I've never seen anything like that.
How would I know if I'm using Servlet 3.9 API or not ?
also, another question, what does this mean: "@Override" - - - I've never seen anything like that.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok on mapping and determining what I am using.
also ok on override, so I'm learning a variety of things here, thanks.
Still tied up though, won't be able to try and fix this until later today or tomorrow morning.
also ok on override, so I'm learning a variety of things here, thanks.
Still tied up though, won't be able to try and fix this until later today or tomorrow morning.
ASKER
Ok, I got the web.xml updated, here:
<servlet>
<servlet-name>fileServlet< /servlet-n ame>
<servlet-class>com.carefir st.edw.web .DownloadS ervlet</se rvlet-clas s>
</servlet>
<servlet-mapping>
<servlet-name>fileServlet< /servlet-n ame>
<url-pattern>/getDoc</url- pattern>
</servlet-mapping>
but now I get the non-informative message: "Error 400: Error reported: 400"
<servlet>
<servlet-name>fileServlet<
<servlet-class>com.carefir
</servlet>
<servlet-mapping>
<servlet-name>fileServlet<
<url-pattern>/getDoc</url-
</servlet-mapping>
but now I get the non-informative message: "Error 400: Error reported: 400"
ASKER
well, I modified the classpath to this:
<servlet-class>WEB-INF.classes.com.carefirst.edw.web.Dow nloadServl et</servle t-class>
and got this error message:
Error 404: SRVE0203E: Servlet [fileServlet]: WEB-INF.classes.com.carefi rst.edw.we b.Download Servlet was found, but is missing another required class. SRVE0206E: This error typically implies that the servlet was originally compiled with classes which cannot be located by the server. SRVE0187E: Check your classpath to ensure that all classes required by the servlet are present.SRVE0210I: This problem can be debugged by recompiling the servlet using only the classes in the application's runtime classpath SRVE0234I: Application classpath=
<servlet-class>WEB-INF.classes.com.carefirst.edw.web.Dow
and got this error message:
Error 404: SRVE0203E: Servlet [fileServlet]: WEB-INF.classes.com.carefi
>"Error 400: Error reported: 400"
That is telling us that the request was bad (syntactically incorrect).
What did you request ?
Are you using the simple test Servlet in my last post ?
Did you browse to
http://localhost:9080/edw/getDoc
?
Is edw the name of your web app ?
><servlet-class>WEB-INF.cl asses.com. carefirst. edw.web.Do wnloadServ let</servl et-class>
That is wrong. You had it right before. Use
<servlet-class>com.carefir st.edw.web .DownloadS ervlet</se rvlet-clas s>
The classes folder is in Tomcat's classpath.
Is the file DownloadServlet.class in
<yourTomcatHome>/webapps/e dw/WEB-INF /classes.c om/carefir st/edw/web
?
Is the first line of your Servlet
package com.carefirst.edw.web;
?
That is telling us that the request was bad (syntactically incorrect).
What did you request ?
Are you using the simple test Servlet in my last post ?
Did you browse to
http://localhost:9080/edw/getDoc
?
Is edw the name of your web app ?
><servlet-class>WEB-INF.cl
That is wrong. You had it right before. Use
<servlet-class>com.carefir
The classes folder is in Tomcat's classpath.
Is the file DownloadServlet.class in
<yourTomcatHome>/webapps/e
?
Is the first line of your Servlet
package com.carefirst.edw.web;
?
ASKER
sorry, here's the request:
http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
the application edw works great, just trying to get this servlet to work.
>Are you using the simple test Servlet in my last post ?
- yes, see below, pretty much as is
>Use <servlet-class>com.carefir st.edw.web .DownloadS ervlet</se rvlet-clas s>
-ok
>Is the file DownloadServlet.class in <yourTomcatHome>/webapps/e dw/WEB-INF /classes.c om/carefir st/edw/web
- yes
now getting this again: "Error 400: Error reported: 400 "
We can do this tomorrow if that's better.
http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
the application edw works great, just trying to get this servlet to work.
>Are you using the simple test Servlet in my last post ?
- yes, see below, pretty much as is
>Use <servlet-class>com.carefir
-ok
>Is the file DownloadServlet.class in <yourTomcatHome>/webapps/e
- yes
now getting this again: "Error 400: Error reported: 400 "
We can do this tomorrow if that's better.
package com.carefirst.edw.web;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DownloadServlet extends HttpServlet {
@Override
public void init(){
System.out.println("init of DownloadServlet");
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
InputStream in = null;
OutputStream out = null;
String fileName = request.getParameter("fileName");
if(fileName != null){
try {
File file = new File(fileName);
String filename = "cdr_report.doc";
FileInputStream fis = new FileInputStream(file);
response.setContentType("application/msword");
out = new BufferedOutputStream(response.getOutputStream());
in = new BufferedInputStream(fis);
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
int c;
while( ( c=in.read() ) != -1 ) out.write( c );
}
catch(FileNotFoundException fnfe){
response.sendError( HttpServletResponse.SC_NOT_FOUND);
}
finally {
if( in != null ) try { in.close(); } catch( Exception e ) {}
if( out != null ) try { out.close(); } catch( Exception e ) {}
}
} else response.sendError( HttpServletResponse.SC_BAD_REQUEST);
}
}
Ok. Tomorrow(morning only) is good for me.
I see the problem. In the code we have
if(fileName != null){
...
} else response.sendError( HttpServletResponse.SC_BAD _REQUEST);
fileName was null therefore the SC_BAD_REQUEST was sent .
You used
http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
But the Servlet is looking for the parameter "fileName"
Try using
http://localhost:9080/edw/getDoc?fileName=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
Java is case sensitive.
I see the problem. In the code we have
if(fileName != null){
...
} else response.sendError( HttpServletResponse.SC_BAD
fileName was null therefore the SC_BAD_REQUEST was sent .
You used
http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
But the Servlet is looking for the parameter "fileName"
Try using
http://localhost:9080/edw/getDoc?fileName=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
Java is case sensitive.
ASKER
I don't get what you are saying . . . fileName should be populated from "request.getParameter("fil eName");"
Here's how I call the servlet in the jsp:
<c:otherwise><a href="getDoc?filename=<c:o ut value="${hist.cdrReportLoc }"/>"><c:o ut value="${hist.procDescript ion}"/></a ></c:other wise>
and it gets formed properly as
http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
Here's how I call the servlet in the jsp:
<c:otherwise><a href="getDoc?filename=<c:o
and it gets formed properly as
http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
ASKER
got it ! woo-hoo !
I had to get the parameter filename in the model, then I had to fiddle with the case and finally got it, yea . . .
I had to get the parameter filename in the model, then I had to fiddle with the case and finally got it, yea . . .
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I should have named the form parameter something else so it would not have been confusing.
One more thing that might be a problem later.
You should really encode the parameter's value when inserting into the query string. The value you posted worked without doing so but you might change it later and it might break the code.
One more thing that might be a problem later.
You should really encode the parameter's value when inserting into the query string. The value you posted worked without doing so but you might change it later and it might break the code.
<a href="<c:url value="getDoc">
<c:param name="fileName" value="${hist.cdrReportLoc}" />
</c:url>">${hist.procDescription}</a>
This way the <c:url> and <c:param> tags will encode any special characters. As you can see I didn't use <c:out> tag around your EL values. That should not be necessary.
ASKER
rrz, ok, thanks again, the users will love it :-)
ASKER
shucks, I got this error when I moved it out of my local development . . .
HTTP Status 404 -
type Status report
message
description The requested resource () is not available.
Apache Tomcat/5.5.31
The URL should work . . .
http://xpc-120268/edwdev/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
same as local development
http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
HTTP Status 404 -
type Status report
message
description The requested resource () is not available.
Apache Tomcat/5.5.31
The URL should work . . .
http://xpc-120268/edwdev/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
same as local development
http://localhost:9080/edw/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
>description The requested resource () is not available.
This message tells us that the file could not be found. In the code
This message tells us that the file could not be found. In the code
catch(FileNotFoundException fnfe){
response.sendError( HttpServletResponse.SC_NOT_FOUND);
}
I guess we could improve this by using
catch(FileNotFoundException fnfe){
response.sendError( HttpServletResponse.SC_NOT_FOUND,"The file " + fileName + " could not be found.");
}
Or if you changed the variable to filename, then use
catch(FileNotFoundException fnfe){
response.sendError( HttpServletResponse.SC_NOT_FOUND,"The file " + filename + " could not be found.");
}
This will send the message along with error.
ASKER
ok, but it's the same data (development), just on a different server. My local development environment and then the regular public dev environment both point to the same database . . .
I'll put the error message in as you describe.
I can open another question for this . . .
I'll put the error message in as you describe.
I can open another question for this . . .
>I can open another question for this . . .
That is not necessary for me. But I will be going offline soon. So if you want someone else to help later today then go ahead.
>ok, but it's the same data (development), just on a different server.
There must some difference. Recheck the file location.
Add the debug code
System.out.println("file path is " + fileName);
right after the line that gets the parameter from the request.
That is not necessary for me. But I will be going offline soon. So if you want someone else to help later today then go ahead.
>ok, but it's the same data (development), just on a different server.
There must some difference. Recheck the file location.
Add the debug code
System.out.println("file path is " + fileName);
right after the line that gets the parameter from the request.
ASKER
ok, I will debug some more but will open another question if I can't fix it. thanks a lot.
ASKER
this is the error message on local development when the file name is bad:
Error 404: The file R:/FTP/Highmark/data/test/ ods_cdr_ta b_cnt_104_ 2011_04_26 _XXX_17_02 .doc could not be found.
it shows up just as written above on a white screen inside a "thick-box" (I forced it to be bad with "XXX")
on the Tomcat server, I get this, also inside the thick-box
HTTP Status 404 - The file R:/FTP/Highmark/data/test/ ods_cdr_ta b_cnt_104_ 2011_04_26 _at_17_02. doc could not be found.
type Status report
message The file R:/FTP/Highmark/data/test/ ods_cdr_ta b_cnt_104_ 2011_04_26 _at_17_02. doc could not be found.
description The requested resource (The file R:/FTP/Highmark/data/test/ ods_cdr_ta b_cnt_104_ 2011_04_26 _at_17_02. doc could not be found.) is not available.
Apache Tomcat/5.5.31
something's obviously different, I'll open another question
Error 404: The file R:/FTP/Highmark/data/test/
it shows up just as written above on a white screen inside a "thick-box" (I forced it to be bad with "XXX")
on the Tomcat server, I get this, also inside the thick-box
HTTP Status 404 - The file R:/FTP/Highmark/data/test/
type Status report
message The file R:/FTP/Highmark/data/test/
description The requested resource (The file R:/FTP/Highmark/data/test/
Apache Tomcat/5.5.31
something's obviously different, I'll open another question
I'm on my out, but I did see your other question. Your url
http://xpc-120268/edwdev/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
still has
filename
when the Servlet is looking for
fileName
Also you should add the <c:url> and <c:param> tags that I posted.
http://xpc-120268/edwdev/getDoc?filename=R:/FTP/Highmark/data/test/ods_cdr_tab_cnt_104_2011_04_26_at_17_02.doc
still has
filename
when the Servlet is looking for
fileName
Also you should add the <c:url> and <c:param> tags that I posted.
ASKER
but why would it work on WebSphere and not Tomcat ? I thought I had resolved the fileNname thing since it worked in development.
Ok, I'll add the <c:url> and <c:parm> and move to the new question, thanks again.
Ok, I'll add the <c:url> and <c:parm> and move to the new question, thanks again.
ASKER
first servlet, aw . . .
ASKER
But the link doesn't work when it's embedded in a JSP page running on Tomcat.
I have verified the links are the same (by copying them out), but it doesn't work when running from the JSP rendered page.
file:///R:/FTP/Highmark/da
file:///R:/FTP/Highmark/da