Struts文件上传问题
中上传文件时遇到问题
我在 struts我的 jsp 文件代码
候选人姓名
候选人当前职称
候选人总经验
目前薪资
期望薪资
准备搬迁
教育
</tr>
<tr>
<td>Key Skill In Field<br /></td>
<td><html:text name="GenerateResumeForm" size="35" property="keySkill"/></td>
</tr>
<tr>
<td>Attach Resume<br /></td>
<td><html:file name="GenerateResumeForm" property="attachFile"/></td>
</tr>
<tr>
<td>Job Description<br /></td>
<td><html:textarea name="GenerateResumeForm" cols="27" rows="5" property="jobDesc"/></td>
</tr>
<tr>
<td><br /></td>
<td><html:submit/></td>
</tr>
</table>
</html:form>
我的 ActionForm 是
包 com.hrstrides.employer.generateResume;
导入 org.apache.struts.upload.FormFile;
public classGenerateResumeForm扩展了org.apache.struts.action.ActionForm{
/**
*
*/
private static final long serialVersionUID = 6895513074470145219L;
private String designation;
private String experiance;
private String jobDesc;
private String currentSalary;
private String expectedSalary;
private String readyToRelocate;
private String education;
private String keySkill;
private FormFile attachFile;
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public String getExperiance() {
return experiance;
}
public void setExperiance(String experiance) {
this.experiance = experiance;
}
public String getJobDesc() {
return jobDesc;
}
public void setJobDesc(String jobDesc) {
this.jobDesc = jobDesc;
}
public String getCurrentSalary() {
return currentSalary;
}
public void setCurrentSalary(String currentSalary) {
this.currentSalary = currentSalary;
}
public String getExpectedSalary() {
return expectedSalary;
}
public void setExpectedSalary(String expectedSalary) {
this.expectedSalary = expectedSalary;
}
public String getReadyToRelocate() {
return readyToRelocate;
}
public void setReadyToRelocate(String readyToRelocate) {
this.readyToRelocate = readyToRelocate;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public String getKeySkill() {
return keySkill;
}
public void setKeySkill(String keySkill) {
this.keySkill = keySkill;
}
public FormFile getAttachFile() {
return attachFile;
}
public void setAttachFile(FormFile attachFile) {
this.attachFile = attachFile;
}
public String getCandidateName() {
return candidateName;
}
public void setCandidateName(String candidateName) {
this.candidateName = candidateName;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
private String candidateName;
}
,action类是
包com.hrstrides.employer.generateResume;
导入java.io.File; 导入 java.io.InputStream;
导入 javax.servlet.http.HttpServletRequest; 导入 javax.servlet.http.HttpServletResponse;
导入 org.apache.struts.action.Action; 导入 org.apache.struts.action.ActionForm; 导入 org.apache.struts.action.ActionForward; 导入 org.apache.struts.action.ActionMapping; 导入 org.apache.struts.upload.FormFile;
public classGenerateResumeActionextendsAction{
private String name;
private String designation;
private String experiance;
private String currentSalary;
private String expectedSalary;
private String relocate;
private String education;
private String keySkill;
private FormFile file;
private String jobDescription;
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse responese)throws Exception{
GenerateResumeForm generateResume = (GenerateResumeForm) form;
name = generateResume.getCandidateName();
designation = generateResume.getDesignation();
experiance = generateResume.getExperiance();
currentSalary = generateResume.getCurrentSalary();
expectedSalary = generateResume.getExpectedSalary();
relocate = generateResume.getReadyToRelocate();
education = generateResume.getEducation();
keySkill = generateResume.getKeySkill();
jobDescription = generateResume.getJobDesc();
// FormFile myFile = generateResume.getAttachFile();
//System.out.println(myFile.getFileSize());
/*
GenereateResumeDAO geneResume = new GenereateResumeDAO(name,designation,experiance,
currentSalary,expectedSalary,relocate,education,keySkill,jobDescription);
if (geneResume.isGenerated()){
System.out.println("True");
}else{
System.out.println("False");
}
*/
return null;
}
}
和错误,如
java.lang.IllegalArgumentException: 参数类型不匹配 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在 java.lang.reflect.Method.invoke(Method.java:597) 在org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1773) 在org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759) 在org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648) 在org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677) 在 org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022) 在 org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811) 在 org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298) 在 org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493) 在 org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816) 在 org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203) 在 org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) 在 org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:710) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261) 在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581) 在 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) 在 java.lang.Thread.run(Thread.java:619)
i have problem in file uploading in struts
my jsp file code
Name Of Candidate
Candidate Current Designation
Candidate Total Experiance
Current Salary
Excpected Salary
Ready To Relocate
Education
</tr>
<tr>
<td>Key Skill In Field<br /></td>
<td><html:text name="GenerateResumeForm" size="35" property="keySkill"/></td>
</tr>
<tr>
<td>Attach Resume<br /></td>
<td><html:file name="GenerateResumeForm" property="attachFile"/></td>
</tr>
<tr>
<td>Job Description<br /></td>
<td><html:textarea name="GenerateResumeForm" cols="27" rows="5" property="jobDesc"/></td>
</tr>
<tr>
<td><br /></td>
<td><html:submit/></td>
</tr>
</table>
</html:form>
my ActionForm is
package com.hrstrides.employer.generateResume;
import org.apache.struts.upload.FormFile;
public class GenerateResumeForm extends org.apache.struts.action.ActionForm {
/**
*
*/
private static final long serialVersionUID = 6895513074470145219L;
private String designation;
private String experiance;
private String jobDesc;
private String currentSalary;
private String expectedSalary;
private String readyToRelocate;
private String education;
private String keySkill;
private FormFile attachFile;
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public String getExperiance() {
return experiance;
}
public void setExperiance(String experiance) {
this.experiance = experiance;
}
public String getJobDesc() {
return jobDesc;
}
public void setJobDesc(String jobDesc) {
this.jobDesc = jobDesc;
}
public String getCurrentSalary() {
return currentSalary;
}
public void setCurrentSalary(String currentSalary) {
this.currentSalary = currentSalary;
}
public String getExpectedSalary() {
return expectedSalary;
}
public void setExpectedSalary(String expectedSalary) {
this.expectedSalary = expectedSalary;
}
public String getReadyToRelocate() {
return readyToRelocate;
}
public void setReadyToRelocate(String readyToRelocate) {
this.readyToRelocate = readyToRelocate;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public String getKeySkill() {
return keySkill;
}
public void setKeySkill(String keySkill) {
this.keySkill = keySkill;
}
public FormFile getAttachFile() {
return attachFile;
}
public void setAttachFile(FormFile attachFile) {
this.attachFile = attachFile;
}
public String getCandidateName() {
return candidateName;
}
public void setCandidateName(String candidateName) {
this.candidateName = candidateName;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
private String candidateName;
}
and action class is
package com.hrstrides.employer.generateResume;
import java.io.File;
import java.io.InputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
public class GenerateResumeAction extends Action {
private String name;
private String designation;
private String experiance;
private String currentSalary;
private String expectedSalary;
private String relocate;
private String education;
private String keySkill;
private FormFile file;
private String jobDescription;
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse responese)throws Exception{
GenerateResumeForm generateResume = (GenerateResumeForm) form;
name = generateResume.getCandidateName();
designation = generateResume.getDesignation();
experiance = generateResume.getExperiance();
currentSalary = generateResume.getCurrentSalary();
expectedSalary = generateResume.getExpectedSalary();
relocate = generateResume.getReadyToRelocate();
education = generateResume.getEducation();
keySkill = generateResume.getKeySkill();
jobDescription = generateResume.getJobDesc();
// FormFile myFile = generateResume.getAttachFile();
//System.out.println(myFile.getFileSize());
/*
GenereateResumeDAO geneResume = new GenereateResumeDAO(name,designation,experiance,
currentSalary,expectedSalary,relocate,education,keySkill,jobDescription);
if (geneResume.isGenerated()){
System.out.println("True");
}else{
System.out.println("False");
}
*/
return null;
}
}
and error like
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1773)
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)
at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648)
at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022)
at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 html:form 标记中添加 enctype 属性,如下所示:
In your html:form tag add enctype attribute, like this: