简体   繁体   English

没有属性的吸气剂方法……错误

[英]No getter method for property… error

I am unable to find out what I am doing wrong. 我无法找出我在做什么错。

I get this error: 我收到此错误:

javax.servlet.jsp.JspException: No getter method for property: "firstname" of bean: "org.apache.struts.validator.DynaValidatorForm"
    at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:915)
    at org.apache.struts.taglib.html.BaseFieldTag.prepareValue(BaseFieldTag.java:126)
    at org.apache.struts.taglib.html.BaseFieldTag.renderInputElement(BaseFieldTag.java:102)
    at org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java:80)
    at org.apache.jsp.login_jsp._jspx_meth_html_005ftext_005f1(login_jsp.java:1095)
    at org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f1(login_jsp.java:1040)
    at org.apache.jsp.login_jsp._jspService(login_jsp.java:759)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

in the struts-config.xml file the tage is used: 在struts-config.xml文件中使用年龄:

<form-bean name="sendContactForm" type="org.apache.struts.validator.DynaValidatorForm">
            <form-property name="firstname" type="java.lang.String" initial="firstname"/>
            <form-property name="lastname" type="java.lang.String" initial="lastname"/>
            <form-property name="emailaddress" type="java.lang.String" initial="email"/>
            <form-property name="subject" type="java.lang.String" initial="subject"/>
            <form-property name="comments" type="java.lang.String" initial="comments"/>
        </form-bean>

and also: 并且:

<action path="/sendContactForm" attribute="sendContactForm" input="/login.jsp"
            name="sendContactForm" scope="request"  parameter="reqCode"
            type="org.springframework.web.struts.DelegatingActionProxy" validate="true">
            <forward name="sendcontacts" path="/login.jsp"/>
        </action>

in Actionform I have: 在Actionform中,我有:

public class ContactAction extends DynaValidatorActionForm {

    private static Logger log = Logger.getLogger(ContactAction.class);


public ActionForward sendContactForm(ActionMapping mapping, ActionForm form,
            HttpServletRequest req, HttpServletResponse resp) throws Exception {
            log.debug("ContactForm--start");


DynaValidatorActionForm sendContactForm = (DynaValidatorActionForm) form;
ActionMessages messages = new ActionMessages();

String firstName = ((String) sendContactForm.get("firstname"));
String lastName = ((String) sendContactForm.get("lastname"));
String emailAddress = ((String) sendContactForm.get("emailaddress"));
String subject = ((String) sendContactForm.get("subject"));
String comments = ((String) sendContactForm.get("comments"));
return mapping.findForward("sendcontacts");

In the jsp file I have: 在jsp文件中,我有:

    <html:form action="/sendContactForm.do?ContactCd=sendContactForm" method="post" styleId="sendContactForm">
    <c:set var="sendContactForm" value="${sendContactForm}" />

    <html:errors/>           



        <label for="firstname">First Name  <span class="asterisk">*</span>
        </label>
            <html:text styleId="firstname" property="firstname" styleClass="form-control tip required"  name="sendContactForm" />



        <label for="lastname">Last Name  <span class="asterisk">*</span>
        </label>
        <html:text styleId="lastname" property="lastname" styleClass="form-control tip pplaceholder" name="sendContactForm"/>



        <label for="emailaddress">Email Address  <span class="asterisk">*</span>
        </label>
        <html:text styleId="emailaddress" property="emailaddress" styleClass="form-control tip pplaceholder"  name="sendContactForm" />


        <label for="subject">Subject  <span class="asterisk">*</span>
        </label>
        <html:text styleId="subject" property="subject" styleClass="form-control tip pplaceholder" name="sendContactForm"/>

             <label for="comments">Comments  <span class="asterisk">*</span>
        </label>
        <html:textarea styleId="comments" property="comments" styleClass="form-control tip pplaceholder" name="sendContactForm"></html:textarea>

</html:form>

I have researched a lot but wasn't success yet. 我研究了很多,但还没有成功。

So, what's wrong? 那怎么了 Thank you. 谢谢。

I am shooting in the dark here(don't have much idea of struts) but seems like you are calling getter function[((String) sendContactForm.get("firstname"));] from some bean and it is giving error no getter function. 我在黑暗中拍摄(对Struts的了解不多),但似乎您正在从某些bean调用getter函数[((String)sendContactForm.get(“ firstname”));],它给出了错误号No吸气功能。 So have you created getter function for "firstname"? 那么,您是否为“名字”创建了getter函数?

Ok. 好。 Got your problem. 有你的问题。

Try this. 尝试这个。

Instead of using "String firstName = ((String) sendContactForm.get("firstname"));" 而不是使用“ String firstName =((String)sendContactForm.get(” firstname“));”

Use this 用这个

String firstName = req.getParameter("firstName")); 字符串firstName = req.getParameter(“ firstName”));

This will solve your issue. 这样可以解决您的问题。 Try it. 试试吧。

Major UPDATE: 主要更新:

I tried out your code with the changes I mentioned here, and the login page with all those five fields are getting displayed with their default initial values that were given in form-bean definition. 我用您在这里提到的更改尝试了您的代码,并且包含所有这五个字段的登录页面都显示了其默认初始值,这些默认值是在Bean定义中给出的。 There are no errors in displaying the page. 显示页面没有错误。

Another thing to note here is that your login.jsp has no submit button and you are not all submitting the form, so the control never comes inside your action class. 这里要注意的另一件事是,您的login.jsp没有提交按钮,并且您也没有全部提交表单,因此控件永远不会进入您的动作类内。

This is the login.jsp 这是login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Form</title>
</head>
<body>
<html:form action="/sendContactForm.do?ContactCd=sendContactForm"
        method="post" styleId="sendContactForm">
        <c:set var="sendContactForm" value="${sendContactForm}" />

        <html:errors />



        <label for="firstname">First Name <span class="asterisk">*</span>
        </label>
        <html:text styleId="firstname" property="firstname"
            styleClass="form-control tip required" name="sendContactForm" />



        <label for="lastname">Last Name <span class="asterisk">*</span>
        </label>
        <html:text styleId="lastname" property="lastname"
            styleClass="form-control tip pplaceholder" name="sendContactForm" />



        <label for="emailaddress">Email Address <span class="asterisk">*</span>
        </label>
        <html:text styleId="emailaddress" property="emailaddress"
            styleClass="form-control tip pplaceholder" name="sendContactForm" />


        <label for="subject">Subject <span class="asterisk">*</span>
        </label>
        <html:text styleId="subject" property="subject"
            styleClass="form-control tip pplaceholder" name="sendContactForm" />

        <label for="comments">Comments <span class="asterisk">*</span>
        </label>
        <html:textarea styleId="comments" property="comments"
            styleClass="form-control tip pplaceholder" name="sendContactForm"></html:textarea>

    </html:form>


</body>
</html>

The jars used are 使用的罐子是

struts-taglib-1.3.10.jar,struts-core-1.3.10.jar,jstl-1.2.jar,commons-validator-1.3.1.jar, commons-logging-1.0.4.jar,commons-digester-1.8.jar,commons-chain-1.2.jar,commons-beanutils-1.8.0.jar,antlr-2.7.2.jar

The following tld's are put inside my WEB-INF 以下tld放在我的WEB-INF

struts-bean.tld, struts-html.tld,struts-logic.tld

If you have any validation, validation.xml may also be present in WEB-INF 如果您有任何验证,WEB-INF中也可能存在validation.xml

ContactAction.java [in your current case, control does not come here] ContactAction.java [在您当前的情况下,控件不在此处]

public class ContactAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest req, HttpServletResponse resp) throws Exception {

        DynaValidatorForm sendContactForm = (DynaValidatorForm) form;
        ActionMessages messages = new ActionMessages();

        String firstName = ((String) sendContactForm.get("firstname"));
        String lastName = ((String) sendContactForm.get("lastname"));
        String emailAddress = ((String) sendContactForm.get("emailaddress"));
        String subject = ((String) sendContactForm.get("subject"));
        String comments = ((String) sendContactForm.get("comments"));
        return mapping.findForward("sendcontacts");
    }
}

Previous edits Usage of sendContactForm.get("firstname") is correct, as you are using DynaValidatorForm . 先前的编辑 sendContactForm.get("firstname")用法正确,因为您正在使用DynaValidatorForm

The error is that your action class is extending the wrong class. 错误是您的动作类正在扩展错误的类。

public class ContactAction extends DynaValidatorActionForm

This is wrong. 错了 You need to extend the Action class ie: 您需要扩展Action类,即:

public class ContactAction extends Action

Also, instead of 另外,代替

DynaValidatorActionForm sendContactForm = (DynaValidatorActionForm) form;

use 采用

DynaValidatorForm sendContactForm = (DynaValidatorForm) form;

Update: In your action class, 更新:在您的动作课中,

what is this method name - sendContactForm ? 方法名称是什么sendContactForm Is there any reason for this? 有什么理由吗?

public ActionForward sendContactForm 

Why don't you change it to public ActionForward execute 为什么不将其更改为public ActionForward execute

I am not very much used to DynaActionForms , always used ActionForm . 我不是很习惯DynaActionForms ,而是经常使用ActionForm

Just out of curiosity, does it work if you change firstname to firstName in form definition and all other places you are referring it? 出于好奇,如果您在表单定义中以及将要引用的所有其他地方将firstname更改为firstName ,它是否起作用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM