下面是我用struts标签写的表单:
<%@ page language="java" pageEncoding="gbk"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
prefix="logic"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"
prefix="tiles"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template"
prefix="template"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested"
prefix="nested"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
<html:base />
<title>insert.jsp</title>
</head>
<body bgcolor="pink">
<html:form action="insert.do" method="post">
id:<html:text property="id"></html:text>
<html:errors property="nid" />
<br>
name:<html:text property="name"></html:text>
<br>
<html:errors property="nname" />
<br>
address:<html:text property="address"></html:text>
<br>
email:<html:text property="email"></html:text>
<br>
<html:submit value="提交" />
<html:reset value="重置" />
</html:form>
</body>
</html:html>
启动服务器之后跳出下列错误:
好像是提示action mapping没有找到或者是没有找到formbean中的集合
我连表单提交都没有提交怎么会有集合元素呢?
到底怎么回事啊?
----------------解决方案--------------------------------------------------------
servlet 异常,说明你的insert.do
获取信息不正确或读取信息不正确,请检查一下。
----------------解决方案--------------------------------------------------------
没有啊,我连表单都没有显示啊,根本连提交都没有提交,actionForm里怎么可能接收到数据呢,读不到任何信息啊,我用的ide是eclipse3.2.0+myeclipse5.1.1ga
----------------解决方案--------------------------------------------------------
虽然你没有提交,它也是会检查的!
----------------解决方案--------------------------------------------------------
这是我的formbean
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.zwj.struts.Form;
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-12-2007
*
* XDoclet definition:
* @struts.form name="InsertForm"
*/
public class InsertForm extends ActionForm {
/*
* Generated fields
*/
/** address property */
private String address;
/** email property */
private String email;
/** name property */
private String name;
/** id property */
private String id;
/*
* Generated Methods
*/
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (id == null || id.trim().length() == 0) {
ActionMessage message = new ActionMessage("error.id");
errors.add("nid", message);
}
if (name == null || name.trim().length() == 0) {
ActionMessage message = new ActionMessage("error.name");
errors.add("nname", message);
}
return errors;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the address.
* @return String
*/
public String getAddress() {
return address;
}
/**
* Set the address.
* @param address The address to set
*/
public void setAddress(String address) {
this.address = address;
}
/**
* Returns the email.
* @return String
*/
public String getEmail() {
return email;
}
/**
* Set the email.
* @param email The email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* Returns the name.
* @return String
*/
public String getName() {
return name;
}
/**
* Set the name.
* @param name The name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* 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;
}
}
下面是我的sturts-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>
<data-sources />
<form-beans >
<form-bean name="InsertForm" type="com.zwj.struts.Form.InsertForm" />
</form-beans>
<global-exceptions />
<global-forwards >
<forward name="fail" path="/error.jsp" />
</global-forwards>
<action-mappings >
<action
attribute="InsertForm"
input="/insert.jsp"
name="InsertForm"
path="/insert"
scope="request"
type="com.zwj.struts.Action.InsertAction" >
<forward name="suc" path="/isuccess.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.zwj.struts.Form.ApplicationResources" />
</struts-config>
我没有发现什么错误啊
----------------解决方案--------------------------------------------------------
因为你没有创建 InsertAction ,struts首先运行的是Action,因为它是处理类,根据配置文件来进行处理,你没有这个Action,当然会报错,不信你创一个Action试试看
----------------解决方案--------------------------------------------------------
action类写错了
----------------解决方案--------------------------------------------------------
你把这些东西都去干净就对了。
<html:errors property="XXX" />
----------------解决方案--------------------------------------------------------