struts 1.2 整合 spring时getServlet() 为空

什么都不能 2008-02-27 01:30:52
<action path="/upload" type="org.springframework.web.struts.DelegatingActionProxy" scope="request" >
</action>


<bean name="/upload" class="com.test.struts.action.UploadAction" singleton="false"></bean>

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
UploadForm f = (UploadForm) form;
FormFile file=f.getAttachment();
byte[] data=file.getFileData();

49: String filePath=getServlet().getServletContext().getRealPath("/upload");
System.out.println(filePath);
FileOutputStream fo=new FileOutputStream(filePath+"/"+file.getFileName());
fo.write(data);
int size=file.getFileSize();
String type=file.getContentType();
Map mp=new HashMap();
mp.put("size", size);
mp.put("type",type);
request.setAttribute("property", mp);
return new ActionForward("/result.jsp");
}
49行报NullPointerException
...全文
287 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
什么都不能 2008-03-02
  • 打赏
  • 举报
回复
拆分测试结果,用DelegetingActionProxy代理时,getServlet()方法返回null
xiaokunyu 2008-03-01
  • 打赏
  • 举报
回复
建議將49行代碼,拆分調試.
miaoliujun 2008-02-29
  • 打赏
  • 举报
回复
是不是没有upload文件夹?
IamHades 2008-02-29
  • 打赏
  • 举报
回复
调试下到底是getServlet()为null还是后面的...
never2cry 2008-02-28
  • 打赏
  • 举报
回复
The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.
never2cry 2008-02-28
  • 打赏
  • 举报
回复
getServlet().getServletContext()? 啥意思啊??

67,542

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧