javax.servlet.ServletException: No getter method for property Admin_Name of bean org.apache.struts.taglib.html.BEAN

本文介绍了Struts框架的基本使用方法,包括如何搭建最简单的Struts应用,以及如何在JSP页面中使用<html:form>标签。文章还详细解释了配置文件struts-config.xml中的ActionMapping和ActionForm的作用,并提供了实例说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Struts :

  在表单提交过程的经验:

在表单的<html:text property="managerName"></html:text>中property和FROM的对应字段名称相符合最好!!!以免出现不必要的错误++ Admin_Name->admin_Name     属性名小写  要不会出现javax.servlet.ServletException: No getter method for property Admin_Name of bean org.apache.struts.taglib.html.BEAN的错误

action 中config配置中FORM和ACTION 是一对多的对应!!

 

 

 

一下是截取http://blog.youkuaiyun.com/hotdust/archive/2007/04/26/1586343.aspx的内容  值得看

1.      在struts中,要得到一个最小化的struts是什么样的呢?
先说说这里最小化的含意。在这里,最小化就是指用struts实现一个JSP页面跳到另一个JSP页面就行。如果你想再小的话,那就只是一个strtus框架了(实现一个struts只要把各个JAR和TLD文件放到相应的LIB和WEB-INF目录中就行了)。下面说说struts这里所说的最小化结构。
最小化的struts只要实现一个Action就行,因为在struts中,ActionServlet是必须有的。ActionServlet是控制器,他要知道你要跳传的页面地址是什么,又因为在strtus架构中规范中,ActionServlet只接收的地址包装所要地址的ActionForward对像。在struts中,(据我现在所知)只有ACTION能返回ActionForward对象。所以,只要实现一个ACTION就可以了。
例:
 
 
2.      如果要实现一个在JSP页面中带有<html:form>的最小struts框架,那又是怎么样的呢?
(1)      在JSP页面中写一个<html:form></html:form>,在<html:form>的action属性设置为”/”
例: < html:form action = "/" > </ html:form >
(2)      在struts-config.xml中,写一个ActionMapping,内容如下:
< action-mappings >
           < action   path = "/" ></ action >
</ action-mappings >
(action和path属性最好写上你已经写好的Action类,这么写的原因是让些JSP可以通过编译)
(3)      接着写一个 ActionForm ,要写完整了,要不然会出错
   < form-beans >
              < form-bean name = "helloForm" type = "hello.HelloForm" >
              </ form-bean >
</ form-beans >
这时,ActionMapping也要改成:
< action-mappings >
         < action    path = "/"
                               type = ""
                              name = "helloForm" >
           </ action >
     </ action-mappings >
要不然会出错
这样,一个有<html:form>的最小strtuts就完成了。
:) 
通过上面的步骤说一说这个带<html:form>最小struts的工作流程吧。
(1)当你把带有<html:form>的JSP写完后,struts-config.xml只写上基本的头时,例: <? xml version = "1.0" encoding = "UTF-8" ?>
<! DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" >
< struts-config ></ struts-config >
编译器会报错:“javax.servlet.ServletException: Cannot retrieve mapping for action /”。由此可以看出,当出现一个<html:form>时,编译器首先要找的是和这个form对应的ActionMappingAction
(2)在把ActionMapping设置成
< action-mappings >
           < action   path = "/" ></ action >
</ action-mappings >
后,再进行编译JSP,编译器会报错:“ javax.servlet.ServletException: Cannot retrieve definition for form bean null”。这是因为编译器接下来想找与<html:form>对应的ActionForm,你的action中没有配置ActionForm的对象,自然就会报错。好,我们把他补上,变成:
< action-mappings >
                  < action    path = "/"
                      type = ""
                      name = "helloForm" >
                 </ action >
</ action-mappings >
(4)      这下会怎么样呢?唉,还会报错,这是为什么?因为当你在action中指定了与form相对应的ActionForm的对象后,编译自动会实例化一个你编写的ActionForm的对象,它在struts-config.xml中找不到〈form-bean〉的配置清单,所以它不能根据〈form-bean〉配置清单创建一个ActionForm的实例,就报出刚才的错误。
(5)      然后我们创建一个ActionForm,这个form要写完整了,可以没有validate方法,和reset方法,但不可以少getXxx和setXxx方法,如果少了这两个方法的话,会报错的。
 
<tr> <td class="left"> <bean:message key="GuItemPropertyDto.countyCode" /> <app:equal name="riskCode" value="120A,120B"> <font color="red">*</font></app:equal> </td> <td class="right"> <input name="InsuredGuRelatedPartyItemDistrictCode" class="codecode" type="text" style="width: 34%" value="<bean:write name='insuredGuRelatedPartyDto' property='itemDistrictCode' filter='true' />" title="<bean:write name='guInsuredPolicyRelatedPartyDto' property='itemDistrictCode' filter='true' />" ondblclick="code_CodeSelect(this,'itemDistrictCode','0,1','Y','fm.InsuredGuRelatedPartyItemCityCode[].value');" onkeyup="code_CodeSelect(this,'itemDistrictCode','0,1','Y','fm.InsuredGuRelatedPartyItemCityCode[].value');" onchange="setUpdateColor(this);code_CodeChange(this,'itemDistrictCode','0,1','Y','fm.InsuredGuRelatedPartyItemCityCode[].value');"> <input name="InsuredGuRelatedPartyItemDistrictCName" class="codename" type="text" style="width: 55%" value="<bean:write name='insuredGuRelatedPartyDto' property='itemDistrictCName' filter='true' />" title="<bean:write name='guInsuredPolicyRelatedPartyDto' property='itemDistrictCName' filter='true' />" onchange="setUpdateColor(this);"> </td> </tr> 这是RelatedPartyInsured.jsp的部分内容,相关联的还有RelatedPartyInsured_data.jsp。这部分代码用于显示itemDistrictCode 区县的信息。 报错 ]] Root cause of ServletException. javax.servlet.jsp.JspException: No getter method for property: "itemDistrictCode" of bean: "insuredGuRelatedPartyDto" at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:987) at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:225) 应该如何解决
最新发布
06-26
手把手搭建一个完整的JavaWeb项目 本案例使用Servlet+jsp制作,用Intellij Idea IDE和Mysql数据库进行搭建,详细介绍了搭建过程及知识点。 主要功能有: 1.用户注册 2.用户登录 3.用户列表展示 4.用户信息修改 5.用户信息删除 涉及到的知识点有: 1.JDBC 2.Servlet 3.过滤器 4.EL与JSTL表达式 1.首先打开mysql数据库 新建一个数据库test,然后生成对应的表结构 CREATE TABLE `user` ( `id` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL, `pwd` varchar(255) NOT NULL, `sex` varchar(255) NOT NULL, `home` varchar(255) NOT NULL, `info` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; INSERT INTO `user` VALUES ('3', '123', '123', '123', '123', '123'); INSERT INTO `user` VALUES ('4', '123123', '123123', '男', '北京', '123123'); 这里使用到了navicat for mysql 这是一种mysql的图形界面化工具,后期可以非常方便的操作数据库。 2.然后打开Intellij Idea 新建一个web项目,步骤详情见(一)。 3.在webroot下的WEB-INF下的lib中导入mysql的驱动jar包。 4.建立对应的包结构 com.javaweb.demo.filter //过滤器 解决中文字符集乱码 com.javaweb.demo.util //数据库连接工具类 com.javaweb.demo.entity //实体类 com.javaweb.demo.dao //数据操作类 com.javaweb.demo.servlet //servlet类 5.在filter下新建一个EncodingFilter类用来解决中文字符集乱码,它需要实现Filter接口,并重写doFilter函数 package com.javaweb.demo.filter; import javax.servlet.*; import java.io.IOException; public class EncodingFilter implements javax.servlet.Filter { public EncodingFilter(){ System.out.println("过滤器构造"); } @Override public void init(FilterConfig filterConfig) throws ServletException { System.out.println("过滤器初始化"); } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { servletRequest.setCharacterEncoding("utf-8"); //将编码改为utf-8 servletResponse.setContentType("text/html;charset=utf-8"); filterChain.doFilter(servletRequest, servletResponse); } @Override public void destroy() { System.out.println("过滤器销毁"); } } 6.到web.xml下进行对EncodingFilter相应的配置 整理语言保留代码,将描述语言更新一遍
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值