开发者

Struts File Upload Problem

开发者 https://www.devze.com 2023-03-18 12:18 出处:网络
i have problem in file uploading in struts my jsp file code Name Of Candidate Candidate Current Designation

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.开发者_StackOverflowHttpServletRequest; 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)


In your html:form tag add enctype attribute, like this:

<html:form enctype="multipart/form-data"></html:form>
0

精彩评论

暂无评论...
验证码 换一张
取 消