小弟的一个网页老是不能出现表单,给大家看一下源码:
register.jsp
<%@ page contentType="text/html;charset=gbk"%>
<%@ page import="java.util.*"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<html:html lang="true">
<head>
<title>用户登录</title>
</head>
<body>
<center>
<h1>用户注册</h1>
<html:form action="/user" method="post">
用户ID:<html:text property="userid"></html:text>
<br>
用户密码:<html:password property="userpwd"></html:password>
<br>
确认密码:<html:password property="confirmpwd"></html:password>
<br>
丢失密码提示问题:<html:text property="userques"></html:text>
<br>
丢失密码问题答案:<html:text property="userans"></html:text>
<br>
验证码:<html:text property="checkcode"></html:text>
<img src="image.jsp"><br>
<input type="hidden" name="status" value="register">
<input type="hidden" name="type" value="1">
<html:submit value="注册"></html:submit>
<html:reset value="重置"></html:reset>
</html:form>
</center>
</body>
</html:html>
其中struts-config.xml代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="userForm" type="org.lxh.myznt.struts.action.UserForm" />  </form-beans>  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="userForm"
      input="/jsp/errors.jsp"
      name="userForm"
      parameter="status"
      path="/user"
      scope="request"
      type="org.lxh.myznt.struts.action.UserAction" >
      <forward name="registersucess" path="/jsp/index.jsp" />
      <forward name="registerfailure" path="/jsp/register.jsp" />
    </action>
  </action-mappings>  <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>
  <message-resources parameter="org.lxh.myzntstruts.ApplicationResources" />
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
  </plug-in>
</struts-config>
出现如下错误:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /jsp/register.jsp:1411: <body>
12: <center>
13: <h1>用户注册</h1>
14: <html:form action="/user" method="post">
15:  用户ID:<html:text property="userid"></html:text>
16:  <br>
17:  用户密码:<html:password property="userpwd"></html:password>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause javax.servlet.ServletException: Exception creating bean of class org.lxh.myznt.struts.action.UserForm: {1}
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.jsp.register_jsp._jspService(register_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause javax.servlet.jsp.JspException: Exception creating bean of class org.lxh.myznt.struts.action.UserForm: {1}
org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:487)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:457)
org.apache.jsp.jsp.register_jsp._jspx_meth_html_005fform_005f0(register_jsp.java:135)
org.apache.jsp.jsp.register_jsp._jspx_meth_html_005fhtml_005f0(register_jsp.java:107)
org.apache.jsp.jsp.register_jsp._jspService(register_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.27
到底是为什么啊?紧急求助中...........SOS

解决方案 »

  1.   

    从你的配置看,你的action应该是个DispatchAction,你的action写的没问题吧?
      

  2.   

    userForm创建有问题啊
    看看是否缺少了哪个属性,如:confirmpwd
      

  3.   

    LS正解,楼主的ActionForm有问题,自己仔细看下
      

  4.   

    UserForm.java如下
    /*
     * Generated by MyEclipse Struts
     * Template path: templates/java/JavaClass.vtl
     */
    package org.lxh.myznt.struts.action;import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionMessage;/** 
     * MyEclipse Struts
     * Creation date: 06-17-2009
     * 
     * XDoclet definition:
     * @struts.form name="userForm"
     */
    public class UserForm extends ActionForm {
    /*
     * Generated fields
     */ /**
     * 
     */
    private static final long serialVersionUID = 1L; /** sex property */
    private String sex; /** usermail property */
    private String usermail; /** userques property */
    private String userques; /** userid property */
    private String userid; /** realname property */
    private String realname; /** userans property */
    private String userans; /** userpwd property */
    private String userpwd;

    private String confirmpwd ; /** grade property */
    private String grade; /** integral property */
    private String integral; /** id property */
    private String id;

    private int type ; private String checkcode ;
    /*
     * Generated Methods
     */ /** 
     * Method validate
     * @param mapping
     * @param request
     * @return ActionErrors
     */
    public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
    // TODO Auto-generated method stub
    ActionErrors errors=new ActionErrors();
    if(type==1){
    if(this.userid==null||"".equals(userid)){
    errors.add("userid",new ActionMessage("user.userid.null"));
    }
    if(this.userpwd==null||"".equals(this.userpwd)){
    errors.add("userpwd",new ActionMessage("user.userpwd.null"));
    }else{
    if(!(this.userpwd.equals(this.confirmpwd))){
    errors.add("confirmpwd",new ActionMessage("user.userconfirmpwd.error"));
    }
    }

    if(this.userques==null||"".equals(this.userques)){
    errors.add("userques", new ActionMessage("user.userques.null"));
    }
    if(this.userans==null||"".equals(this.userans)){
    errors.add("userans", new ActionMessage("user.userans.null"));
    }
    if(this.checkcode==null||"".equals(this.checkcode)){
    errors.add("checkcode", new ActionMessage("checkcode.null"));
    }

    }

    return errors;
    } /** 
     * Method reset
     * @param mapping
     * @param request
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
    // TODO Auto-generated method stub
    } /** 
     * Returns the sex.
     * @return String
     */
    public String getSex() {
    return sex;
    } /** 
     * Set the sex.
     * @param sex The sex to set
     */
    public void setSex(String sex) {
    this.sex = sex;
    } /** 
     * Returns the usermail.
     * @return String
     */
    public String getUsermail() {
    return usermail;
    } /** 
     * Set the usermail.
     * @param usermail The usermail to set
     */
    public void setUsermail(String usermail) {
    this.usermail = usermail;
    } /** 
     * Returns the userques.
     * @return String
     */
    public String getUserques() {
    return userques;
    } /** 
     * Set the userques.
     * @param userques The userques to set
     */
    public void setUserques(String userques) {
    this.userques = userques;
    } /** 
     * Returns the userid.
     * @return String
     */
    public String getUserid() {
    return userid;
    } /** 
     * Set the userid.
     * @param userid The userid to set
     */
    public void setUserid(String userid) {
    this.userid = userid;
    } /** 
     * Returns the realname.
     * @return String
     */
    public String getRealname() {
    return realname;
    } /** 
     * Set the realname.
     * @param realname The realname to set
     */
    public void setRealname(String realname) {
    this.realname = realname;
    } /** 
     * Returns the userans.
     * @return String
     */
    public String getUserans() {
    return userans;
    } /** 
     * Set the userans.
     * @param userans The userans to set
     */
    public void setUserans(String userans) {
    this.userans = userans;
    } /** 
     * Returns the userpwd.
     * @return String
     */
    public String getUserpwd() {
    return userpwd;
    } /** 
     * Set the userpwd.
     * @param userpwd The userpwd to set
     */
    public void setUserpwd(String userpwd) {
    this.userpwd = userpwd;
    } /** 
     * Returns the grade.
     * @return String
     */
    public String getGrade() {
    return grade;
    } /** 
     * Set the grade.
     * @param grade The grade to set
     */
    public void setGrade(String grade) {
    this.grade = grade;
    } /** 
     * Returns the integral.
     * @return String
     */
    public String getIntegral() {
    return integral;
    } /** 
     * Set the integral.
     * @param integral The integral to set
     */
    public void setIntegral(String integral) {
    this.integral = integral;
    } /** 
     * Returns the id.
     * @return String
     */
    public String getId() {
    return id;
    } /** 
     * Set the id.
     * @param id The id to set
     */
    public void setId(String id) {
    this.id = id;
    } public String getConfirmpwd() {
    return confirmpwd;
    } public void setConfirmpwd(String confirmpwd) {
    this.confirmpwd = confirmpwd;
    } public static long getSerialVersionUID() {
    return serialVersionUID;
    } public int getType() {
    return type;
    } public void setType(int type) {
    this.type = type;
    } public String getCheckcode() {
    return checkcode;
    } public void setCheckcode(String checkcode) {
    this.checkcode = checkcode;
    }
    }
      

  5.   

    你的actionform中的属性定义和你在jsp中的标记的属性名称不相符,看看是不是jsp中有没有定义的。
      

  6.   

    UserAction如下;
    /*
     * Generated by MyEclipse Struts
     * Template path: templates/java/JavaClass.vtl
     */
    package org.lxh.myznt.struts.action;import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionMessage;
    import org.apache.struts.action.ActionMessages;
    import org.apache.struts.actions.DispatchAction;
    import org.lxh.myznt.dao.IUserDAO;
    import org.lxh.myznt.vo.User;/** 
     * MyEclipse Struts
     * Creation date: 06-17-2009
     * 
     * XDoclet definition:
     * @struts.action path="/user" name="userForm" input="/jsp/errors.jsp" parameter="status" scope="request" validate="true"
     */
    public class UserAction extends DispatchAction {
    /*
     * Generated Methods
     */
    private IUserDAO iuserdao;
    /** 
     * Method execute
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
    public ActionForward register(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
    UserForm userForm = (UserForm) form;
    String ccode=(String)request.getSession().getAttribute("ccode");
    String checkcode=userForm.getCheckcode();
    if(!(checkcode.equals(ccode))){
    ActionMessages errors=new ActionMessages();
    errors.add("checkcode",new ActionMessage("checkcode.error"));
    super.saveErrors(request, errors);
    return mapping.getInputForward();
    }
    //如果正确则需要向数据库插入
    User user=new User();
    user.setUserid(userForm.getUserid());
    user.setUserpwd(userForm.getUserpwd());
    user.setUserques(userForm.getUserques());
    user.setUserans(userForm.getUserans());
    user.setGrade(1);

    try {
    //成功之后将用户名和登记保存你在session中
    this.iuserdao.register(user);
    request.getSession().setAttribute("userid", user.getUserid());
    request.getSession().setAttribute("grade", String.valueOf(user.getGrade()));
    return mapping.findForward("registersucess");
    } catch (Exception e) {
    e.printStackTrace();
    return mapping.findForward("registerfailure");
    } }
    public IUserDAO getIuserdao() {
    return iuserdao;
    }
    public void setIuserdao(IUserDAO iuserdao) {
    this.iuserdao = iuserdao;
    }
    }
      

  7.   

    楼主引用struts的时候试试这个指令
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    引用的uri不同
      

  8.   

    from 表单有问题,action 提交路径不对!
      

  9.   

    给你个参考的: <action-mappings >     
       <action path="/BfspAction" 
       type="com.czsb.djgl.action.BfspAction"
       name="BfspForm" 
    scope="request" 
    parameter="operate" 
    validate="false">
       <forward name="bfsp_list" path="/bfsp_list.jsp"></forward>
       <forward name="bfsh_list" path="/bfsh_list.jsp"></forward>
       <forward name="bfcx_list" path="/bfcx_list.jsp"></forward> 
       <forward name="lxName_list" path="/lxName_list.jsp"></forward>    
      
       </action> 
    <html:text name="BfspForm" property="startTime" styleClass="input" size="20" />
      

  10.   

    14: <html:form action="/user" method="post"> 
    ->
    14: <html:form action="/user.do" method="post">