日期:2014-05-17  浏览次数:20769 次

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>
&n