有两个问题:
第1个问题: 我用jspSmartUpload做的上传文件到服务器的mySQL数据库里,保存输入的文本信息都没有问题,当我要从本地上传一个图片文件到服务器端的数据库里时候总是有问题,错误信息如下:
org.apache.jasper.JasperException: An exception occurred processing JSP page /upload.jsp at line 5956: //store the upload file in the databank
57:
58: file = new java.io.File(fullName);
59: fis = new java.io.FileInputStream(file);
60: // out.println(file.length());
61: }
62: //open the databankjava.io.FileNotFoundException: F:\private\bank\bank\images\bg.jpg (No such file or directory)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(FileInputStream.java:106)
org.apache.jsp.upload_jsp._jspService(upload_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)我的upload.jsp里一段相应程序是:
...
String myFileName = "";
String fullName = "";
String editor = (String) request.getSession().getAttribute("logUserName");
java.io.File file = null;
java.io.FileInputStream fis = null;
if (!myFile.isMissing())
{
//get the name of the upload file
myFileName = myFile.getFileName();
fullName = myFile.getFilePathName();
System.out.println("fullName = " + fullName);
//get the name the file without suffix
String suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
//get suffix of the file
String ext= mySmartUpload.getFiles().getFile(0).getFileExt();
//get the size of the file
int fileSize=myFile.getSize();
//store the path
//String aa=getServletContext().getRealPath("/")+"jsp\\";
//String trace=aa+myFileName;
//get other parameters
//String send=(String)mySmartUpload.getRequest().getParameter("send");
//store the file in server
//myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
//store the upload file in the databank
file = new java.io.File(fullName);
fis = new java.io.FileInputStream(file);
// out.println(file.length());
}第2个:同样也是文件上传问题,jsp文件里有个打开文本文件并提取其中内容的功能,但是程序部署到服务器后,打不开本地的文件,错误的jsp内容:
The content of the file 'F:\private\bank\bank\images\search.jpg ' : Error: The file 'F:\private\bank\bank\images\search.jpg' does not exists.
Do you want to look at another file?
相应的程序:
<% if (file_reader.getFileName() != "") { %> <b>The content of the file '</b><% out.println(file_reader.getFileName()); %><b>' : </b>
<br><br> 这些问题当在本机上运行程序时候都不存在,当把程序发布到服务器端后才出现的问题,估计是相对路径的设置问题,请教各位高手应该怎么修改程序,小弟谢谢了!!
第1个问题: 我用jspSmartUpload做的上传文件到服务器的mySQL数据库里,保存输入的文本信息都没有问题,当我要从本地上传一个图片文件到服务器端的数据库里时候总是有问题,错误信息如下:
org.apache.jasper.JasperException: An exception occurred processing JSP page /upload.jsp at line 5956: //store the upload file in the databank
57:
58: file = new java.io.File(fullName);
59: fis = new java.io.FileInputStream(file);
60: // out.println(file.length());
61: }
62: //open the databankjava.io.FileNotFoundException: F:\private\bank\bank\images\bg.jpg (No such file or directory)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(FileInputStream.java:106)
org.apache.jsp.upload_jsp._jspService(upload_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)我的upload.jsp里一段相应程序是:
...
String myFileName = "";
String fullName = "";
String editor = (String) request.getSession().getAttribute("logUserName");
java.io.File file = null;
java.io.FileInputStream fis = null;
if (!myFile.isMissing())
{
//get the name of the upload file
myFileName = myFile.getFileName();
fullName = myFile.getFilePathName();
System.out.println("fullName = " + fullName);
//get the name the file without suffix
String suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
//get suffix of the file
String ext= mySmartUpload.getFiles().getFile(0).getFileExt();
//get the size of the file
int fileSize=myFile.getSize();
//store the path
//String aa=getServletContext().getRealPath("/")+"jsp\\";
//String trace=aa+myFileName;
//get other parameters
//String send=(String)mySmartUpload.getRequest().getParameter("send");
//store the file in server
//myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
//store the upload file in the databank
file = new java.io.File(fullName);
fis = new java.io.FileInputStream(file);
// out.println(file.length());
}第2个:同样也是文件上传问题,jsp文件里有个打开文本文件并提取其中内容的功能,但是程序部署到服务器后,打不开本地的文件,错误的jsp内容:
The content of the file 'F:\private\bank\bank\images\search.jpg ' : Error: The file 'F:\private\bank\bank\images\search.jpg' does not exists.
Do you want to look at another file?
相应的程序:
<% if (file_reader.getFileName() != "") { %> <b>The content of the file '</b><% out.println(file_reader.getFileName()); %><b>' : </b>
<br><br> 这些问题当在本机上运行程序时候都不存在,当把程序发布到服务器端后才出现的问题,估计是相对路径的设置问题,请教各位高手应该怎么修改程序,小弟谢谢了!!
解决方案 »
- 请问下,我保存网站的背景图片,发现就一张大图,怎么回事呢?
- 在家自学Jsp,学到第几章以后能做出留言板和电子商城?
- 调用webservice问题,在线等
- 谁能详细的讲一下Servlet中doGet()和doPost()的作用和区别?
- jsp页面跳转
- 当WEB后台程序执行比较费时的操作时,该如何处理
- ext 4.2.1 gridpanel动态创建列和数据
- 需要定义一个未知大小的数组,请问如何初始化!万分谢谢~~在线等!
- JSP页面读不到Map的值
- netty做通讯业务,如何做负载?
- Linux es4.6 tomcat6.0.14报错:java.sql.SQLException: Io 异常: Broken pipe
- 问一个面向对象的基本问题,麻烦各位能看看!
另外:建议用相对的路径!
看一下,这个帖子吧
http://topic.csdn.net/u/20080605/17/22078447-285a-4536-aecc-7284e19baced.html
F:\private\bank\bank\images\ 这个路径在本机上是存在的,文件也都有。另请教如何使用相对路径
本机上你测试了没有?成功了没有?建议用struts自带的FileForm