1.form 的代码
package com.randy.nrs.login.form;

import org.apache.struts.action.ActionForm;

import com.randy.nrs.login.bean.UserBean;

public class LoginForm extends ActionForm {

  private UserBean detailObject =new UserBean();

  public UserBean getDetailObject() {
    return detailObject;
  }

  public void setDetailObject(UserBean detailObject) {
    this.detailObject = detailObject;
  }
    

}
 
 
2. jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld"%>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld"%>
<%@ taglib prefix="logic" uri="/WEB-INF/struts-logic.tld"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>登录页面</title>
</head>
<body>
<html:form action="loginAction" method="post">
  用户名:<html:text property="detailObject.username"></html:text><br/>
  密码:<html:password property="detailObject.password"></html:password><br/>
  <html:submit>提交</html:submit>
</html:form>
</body>
</html>
 
 
遇到的错误
org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Invalid argument looking up property: "bean.property" of bean:
"org.apache.struts.taglib.html.BEAN"
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:960)
at org.apache.struts.taglib.html.BaseFieldTag.prepareValue(BaseFieldTag.java:121)
at org.apache.struts.taglib.html.BaseFieldTag.renderInputElement(BaseFieldTag.java:102)
at org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java:81)
在网上找到的解决方案:
这是个隐含其它异常的异常,光看异常提示,是解决不了问题的
错误提示,找不到bean.property属性实际是个假像,实际上因为hibernate的lazy=true后,在action中处理时
bean是个被lazy掉的对像,照常赋值,但formBean的bean属性没有被初始化,所以会出现上述错误
解决办法是,将bean放入formBean之前,先将其初始化。
 
将应用的form 对象,引用的userbean 初始化了。
private UserBean detailObject =new UserBean();