当前位置: 代码迷 >> Java Web开发 >> Struts2 下传有关问题,求大侠帮忙
  详细解决方案

Struts2 下传有关问题,求大侠帮忙

热度:6015   发布时间:2013-02-25 21:11:40.0
Struts2 上传问题,求大侠帮忙!
错误提示:

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)


root cause 

org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
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)
org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:139)
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
......



action代码

public class Upload extends ActionSupport {
private String title;
private File upload;
private String uploadContentType;
private String filePath;
private String uploadFileName;

//get Set方法省略。。。。

public String excute() throws Exception
{
//以服务器的文件保存地址和原文件名建立上传文件输出流
FileOutputStream fos=new FileOutputStream(getFilePath()+"\\"+getUploadFileName());
//以上传文件建立一个文件上传流
FileInputStream fis=new FileInputStream(getUpload());
//将上传文件的内容写入服务器
byte[] buffer=new byte[1024];
int len=0;
while((len=fis.read(buffer))>0)
{
fos.write(buffer,0,len);
}
return "succ";
}




struts 2 ation配置
  <action name="upload" class="com.login.action.Upload" method="excute">
  <param name="filePath">/upload</param>
  <result name="succ">test.jsp</result>
  <result name="error">error.jsp</result>  
  </action>



web配置 

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <filter>
  <filter-name>struts-cleanup</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts-cleanup</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  
  <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>



------解决方案--------------------------------------------------------
报的异常属于空指针,你贴的异常信息不全所以不能准确的定位到哪一句报的空指针异常
FileOutputStream fos=new FileOutputStream(getFilePath()+"\\"+getUploadFileName());
//以上传文件建立一个文件上传流
FileInputStream fis=new FileInputStream(getUpload());
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Sat Sep 23 09:58:16 CST 2017
  • 最近登录:Sat Sep 23 09:58:16 CST 2017
  • 最近登录:Sat Sep 23 09:58:16 CST 2017
  • 最近登录:Sat Sep 23 09:58:16 CST 2017
  • 最近登录:Sat Sep 23 09:58:16 CST 2017