我有一个问题,我需要帮助。我在 Eclipse 中使用 Struts 1.3.10,我正在开发一个 Web 应用程序,我正在使用 JSP,好吧,我正在实现一个上传文件的 JSP,但给我带来了问题。我有下一个代码和配置。
<body>
<html:form action="upload" method="post" enctype="multipart/form-data">
<input type="file" name="fichier" />
<tr>
<td><html:submit property="submit" value="Submit"/></td>
<td align="left"><html:reset/></td>
</tr>
</html:form>
</body>
在Form bean中我有
public class uploadForm extends ActionForm {
protected FormFile fichier;
public FormFile getFichier()
{
return fichier;
}
public void setFile(FormFile fichier)
{
this.fichier = fichier;}}
在我的行动中
public class uploadAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest req,
HttpServletResponse res) throws Exception {
String resultat = null;
FormFile fichier = ((uploadForm) form).getFichier();
String fileName = fichier.getFileName();
System.out.println(fileName);
return mapping.findForward(resultat);
}
}
在我的 struts-config 中
<form-beans type="org.apache.struts.action.ActionFormBean">
<form-bean name="uploadForm" type="struts.ActionForm.uploadForm" />
</form-beans><action-mappings type="org.apache.struts.action.ActionMapping">
<action path="/fiche" input="/FormulaireFiche.jsp" scope="request"
name="FicheRenseignementForm" type="struts.action.FicheRenseignementAction">
<forward name="succes" path="/personnel_succes.jsp" redirect="false" />
<forward name="echec" path="/FormulaireFiche.jsp" redirect="false" />
</action></action-mappings>
当我运行应用程序并选择文件时,服务器向我发送异常
javax.servlet.ServletException: java.lang.NullPointerException
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
起因
java.lang.NullPointerException
struts.action.uploadAction.execute(uploadAction.java:21)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)