JSP File Viewer Problem: Error 404

M

Matt

I have a JSP page that allows to select a file, and it will displays
the file. However, it
has Error 404 in fileview2.jsp. What did I miss here? please help.
thanks!!

//fileview.jsp
<FORM ACTION="fileview2.jsp" method="POST">
<P><input type="FILE" name="filename">
<P><input type="submit">

//fileview2.jsp
<%
//Error 404: File not found: uploaddoc/C:/file.doc
String filename = request.getParameter("filename");
response.addHeader("content-type", "text/plain");
response.sendRedirect(filename);
%>
 
A

Andrew Thompson

//fileview.jsp
<FORM ACTION="fileview2.jsp" method="POST">

Try a 'get' when you are having problems,
*see* what you are receiving at page 2..
<P><input type="FILE" name="filename">
<P><input type="submit">
</FORM>

...make sure the HTML produced by
your .JSP's is valid HTML, use the
validator as your guide.
//fileview2.jsp
<%
//Error 404: File not found: uploaddoc/C:/file.doc
String filename = request.getParameter("filename");

// you should be checking it here as well,
// if something is awry
System.out.println("filename: " + filename);
response.addHeader("content-type", "text/plain");
response.sendRedirect(filename);
%>

See how that goes, if it suggests a source
of the error, and/or the fix.

HTH
 
K

kaeli

I have a JSP page that allows to select a file, and it will displays
the file. However, it
has Error 404 in fileview2.jsp. What did I miss here? please help.
thanks!!

//fileview.jsp
<FORM ACTION="fileview2.jsp" method="POST">
<P><input type="FILE" name="filename">

This selects a file from the user's HD and uploads the content. Is that what
you want?
<P><input type="submit">

//fileview2.jsp
<%
//Error 404: File not found: uploaddoc/C:/file.doc
String filename = request.getParameter("filename");

Um, I don't think this isn't how one processes a type=file thing, since a
file would be multipart form data, not a string.
Since the last I tried was in ASP, I could be wrong with JSP, but I don't
think this is right if you're trying to get a file from the user. You'd need
an input stream, I think.
response.addHeader("content-type", "text/plain");
response.sendRedirect(filename);
%>

What exactly are you trying to do here?

--
 
S

Sudsy

Matt said:
I have a JSP page that allows to select a file, and it will displays
the file. However, it
has Error 404 in fileview2.jsp. What did I miss here? please help.
thanks!!

//fileview.jsp
<FORM ACTION="fileview2.jsp" method="POST">

Add this:
enctype="multipart/form-data"
<P><input type="FILE" name="filename">
<P><input type="submit">

//fileview2.jsp
<%
//Error 404: File not found: uploaddoc/C:/file.doc
String filename = request.getParameter("filename");
response.addHeader("content-type", "text/plain");
response.sendRedirect(filename);
%>

You need a content handler for the upload. There's one in Jakarta
commons and also in Struts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top