我用的ssh框架,action继承的是LookupDispatchAction,form用的是LazyValidatorForm,
在做文件上传时遇到了这个错误,已经调了一上午了,未果,来向各位讨教一下HTTP Status 500 : No action instance for path /addManager could be created。
The server encountered an internal error (No action instance for path /addManager could
be created) that prevented it from fulfilling this request。theme_add.jsp主要代码:<html:form action="addManager.do" method="post" enctype="multipart/form-data" >
<table align="center" border="1" width="80%" height="80%">
<tr>
<td align="center">上传附件:</td>
<td><html:file property="theFile"/></td>
<td align="center">
<html:submit property="method">
<bean:message key="theme.up" />
</html:submit>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<html:submit property="method">
<bean:message key="theme.submit"/>
</html:submit><br>
</td>
</tr>
</table>
</html:form>struts-config.xml:<form-bean name="themeForm" type="org.apache.struts.validator.LazyValidatorForm"/>
<action input="/bbs/portal/theme_add.jsp"
name="themeForm"
path="/addManager"
parameter="method"
type="cn.dawning.bbs.web.portal.action.AddManagerAction" >
<forward name="themeAdd" path="/bbs/portal/theme_add.jsp"/>
</action>
AddManagerAction.java:package cn.dawning.bbs.web.portal.action;
public class AddManagerAction extends BaseLookupDispatchAction {
public ActionForward themeUp(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
FileNotFoundException, IOException {
User user = (User)request.getSession().getAttribute("user");
LazyValidatorForm themeForm = (LazyValidatorForm)form;
FormFile file = (FormFile)themeForm.get("theFile");
String contentType = file.getContentType();
String fileName = file.getFileName();
int fileSize = file.getFileSize();
byte[] fileData=file.getFileData();
Date date=new Date();
DateFormat dateFormat=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);
String time=dateFormat.format(date);
Attachment attach = new Attachment();
attach.setContentType(contentType);
attach.setFileName(fileName);
attach.setFileSize(fileSize);
attach.setSubmitTime(time);
attach.setUser(user);
String dir=request.getSession().getServletContext().getRealPath("attachment")+File.separator;
FileOutputStream out = new FileOutputStream(new File(dir+fileName));
out.write(fileData);
out.close();
request.getSession().setAttribute("attach", attach);
ActionForward af = mapping.findForward("themeAdd");
return af;
}
protected Map<String,String> getKeyMethodMap(){
Map<String,String> map = new HashMap<String,String>();
map.put("theme.up","themeUp");
return map;
}
}ApplicationResources.properties:theme.up=上传
theme.submit=提交
在做文件上传时遇到了这个错误,已经调了一上午了,未果,来向各位讨教一下HTTP Status 500 : No action instance for path /addManager could be created。
The server encountered an internal error (No action instance for path /addManager could
be created) that prevented it from fulfilling this request。theme_add.jsp主要代码:<html:form action="addManager.do" method="post" enctype="multipart/form-data" >
<table align="center" border="1" width="80%" height="80%">
<tr>
<td align="center">上传附件:</td>
<td><html:file property="theFile"/></td>
<td align="center">
<html:submit property="method">
<bean:message key="theme.up" />
</html:submit>
</td>
</tr>
<tr>
<td align="center" colspan="3">
<html:submit property="method">
<bean:message key="theme.submit"/>
</html:submit><br>
</td>
</tr>
</table>
</html:form>struts-config.xml:<form-bean name="themeForm" type="org.apache.struts.validator.LazyValidatorForm"/>
<action input="/bbs/portal/theme_add.jsp"
name="themeForm"
path="/addManager"
parameter="method"
type="cn.dawning.bbs.web.portal.action.AddManagerAction" >
<forward name="themeAdd" path="/bbs/portal/theme_add.jsp"/>
</action>
AddManagerAction.java:package cn.dawning.bbs.web.portal.action;
public class AddManagerAction extends BaseLookupDispatchAction {
public ActionForward themeUp(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
FileNotFoundException, IOException {
User user = (User)request.getSession().getAttribute("user");
LazyValidatorForm themeForm = (LazyValidatorForm)form;
FormFile file = (FormFile)themeForm.get("theFile");
String contentType = file.getContentType();
String fileName = file.getFileName();
int fileSize = file.getFileSize();
byte[] fileData=file.getFileData();
Date date=new Date();
DateFormat dateFormat=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);
String time=dateFormat.format(date);
Attachment attach = new Attachment();
attach.setContentType(contentType);
attach.setFileName(fileName);
attach.setFileSize(fileSize);
attach.setSubmitTime(time);
attach.setUser(user);
String dir=request.getSession().getServletContext().getRealPath("attachment")+File.separator;
FileOutputStream out = new FileOutputStream(new File(dir+fileName));
out.write(fileData);
out.close();
request.getSession().setAttribute("attach", attach);
ActionForward af = mapping.findForward("themeAdd");
return af;
}
protected Map<String,String> getKeyMethodMap(){
Map<String,String> map = new HashMap<String,String>();
map.put("theme.up","themeUp");
return map;
}
}ApplicationResources.properties:theme.up=上传
theme.submit=提交
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货