Struts动作类无法获取textarea的值

时间:2017-06-07 13:43:29

标签: java html struts2

我写了下面的代码,一旦我提交表单,就将注释textarea的值传递给struts的action类。但是,当我运行代码时,Actions类无法获取textarea的值。你能告诉我我的代码有什么问题吗?提前谢谢。

<s:form method="post" id="formregister" action="survey" enctype="multipart/form-data">
    <textarea name="surveyComments" id="surveyComments" rows=4 cols=80 wrap=virtual 
        onkeydown="textCounter( this, f.Surv_Q99Count, 255 );" 
        onkeyup="textCounter( this, f.Surv_Q99Count, 255 );">
    </textarea>
</s:form>

以下是我的struts.xml

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.enable.DynamicMethodInvocation"
        value="false" />
    <constant name="struts.devMode" value="false" />
    <constant name="struts.custom.i18n.resources"
        value="ApplicationResources" />
    <constant name="struts.multipart.maxSize" value="5242880" />
    <constant name="struts.convention.action.suffix" value="Controller"/>
    <constant name="struts.convention.action.mapAllMatches" value="true"/>
    <constant name="struts.convention.default.parent.package" value="rest-default"/>
    <constant name="struts.convention.package.locators" value="rest"/>

    <package name="default" extends="struts-default" namespace="/">
        <action name="survey" class="eidms.survey.Survey">
            <interceptor-ref name="defaultStack"/> 
            <interceptor-ref name="fileUpload">   

            </interceptor-ref>

            <result name="success">Confirmation.jsp</result>
            <result name="error">error.jsp</result>
         </action>
    </package>
</struts>

以下是动作类

package eidms.survey;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Map;
import java.util.Properties;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.net.ssl.HttpsURLConnection;
import javax.servlet.http.HttpServletRequest;
import javax.xml.rpc.ServiceException;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.siebel.SurveyWebService.CreateSurvey;
import com.siebel.SurveyWebService.CreateSurvey_Input;
import com.siebel.SurveyWebService.CreateSurvey_Output;
import com.siebel.SurveyWebService.QuerySurvey_Output;
import com.siebel.SurveyWebService.Survey_spcWebservice;
import com.siebel.SurveyWebService.Survey_spcWebserviceStub;
import com.siebel.SurveyWebService.UNINCustomerSurveyWSLocator;

public class Survey extends ActionSupport {
    private String surveyComments;
    final static Logger logger = Logger.getLogger(Survey.class);

    public String execute() {
        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext()
                .get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);
        Boolean isResponseCorrect = Boolean.FALSE;

        System.out.println("Comments are"+getComments());
        return "success";
    }

    public String getComments() {
        return surveyComments;
    }

    public void setComments(String surveyComments) {
        this.surveyComments = surveyComments;
    }
}

我得到了以下输出

 Comments are null

0 个答案:

没有答案