首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2013-09-11 
Struts2 上传问题,求大侠帮忙!错误提示:type Exception reportmessagedescription The server encountered

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());


你完全可以直接用定义的变量
FileOutputStream fos=new FileOutputStream(filePath+"\\"+uploadFileName);
FileInputStream fis=new FileInputStream(upload);

[解决办法]
你的表单配置是什么?

需要<form enctype="multipart/form-data" action="" method="post">
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行