struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ahmed Khan <>
Subject Fileupload misbehaving
Date Fri, 20 Jul 2012 18:40:34 GMT

I have a struts 2 application where 2 pages have struts file upload. One
works perfectly while the other just wont work. I gives me* "**Invalid
field value for field "secImage"*.

Here is the code for JSP

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib uri="" prefix="display" %>

        <%@ include file="header.jsp" %>

        <s:form action="Test" method="POST" style="width:90%;">
               Another form here......
        <s:form action="saveOrUpdateVulMGR" method="POST"
enctype="multipart/form-data" style="width:65%;">
            <s:push value="secVul">
                <s:hidden name="vulId" />
                <s:hidden name="scanHistory.scanId" />
                <s:textfield name="protocol" label="Protocol" style="width:
80%;" />
                <s:textarea name="description" label="Description"
style="width: 80%;" />
                <s:textarea name="solution" label="solution" />
                <more form elements here>sdfasdfasdfasd

*                <s:file name="secImage" label="Image to Upload" size="40"/>
                <s:submit value="Add/Update" align="center"/>
<%@ include file="footer.jsp" %>

*Here is the struts configuration*

                <interceptor-ref name="fileUpload">
                    <param name="maximumSize">909715200</param>
                    <param name="allowedTypes">

                <interceptor-ref name="defaultStack" />

        <action name="Test" method="saveOrUpdate" class="com.Test">
            <result name="success" type="redirect">listVulsMGR</result>
            <result name="input">/WEB-INF/pages/secVuls.jsp</result>
            <result name="error">/WEB-INF/pages/secVuls.jsp</result>

*Action Class Code:*

public class Test extends ActionSupport implements ModelDriven<Test>,
Preparable,ServletRequestAware {

    private HttpServletRequest servletRequest;
    private static final Logger logger =

    private File secImage;
    private String secImageContentType;
    private String secImageFileName;

    private HashMap userFilters = new HashMap();
    public Test() {


    public String saveOrUpdate() {
        try {

            ServletContext context =
            String filePath = context.getInitParameter("UploadDirectory");
            logger.debug("Server path:" + filePath);
            logger.debug("this.secImageFileName " + this.secImageFileName);

            File fileToCreate = new File(filePath, this.secImageFileName);

            FileUtils.copyFile(this.secImage, fileToCreate);

            addActionMessage("successfully added/updated.");
            return SUCCESS;
        } catch (Exception ex) {
            logger.error("Error in Test", ex);
            addActionError("Error occured in Test. Please contact your
administrator.\n" + ex.getMessage());
            return ERROR;



Not sure what I am doing wrong here.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message