struts 1.2 整合 spring时getServlet() 为空

什么都不能 什么都不能 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<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
...全文
评论 6
收藏 已收藏
分享
返回顶部
什么都不能
Java EE 67,535 成员 225,843 内容