Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Servlet/JSP/JSF/JavaFX Script  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 struts表单检测不能显示数据错误???
mybillliu





发贴: 11
于 2004-08-02 16:29 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
--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>
<form-beans>
<!--form-bean name="editForm" type="userval.EditForm" /-->
<form-bean name="editForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="name" type="java.lang.String"/>
<form-property name="pwd1" type="java.lang.String"/>
<form-property name="pwd2" type="java.lang.String"/>
<form-property name="address" type="java.lang.String"/>
</form-bean>
</form-beans>
<global-forwards>
<forward name="index" path="/index.jsp" />
<forward name="success" path="/success.jsp" />
</global-forwards>
<action-mappings>
<action input="index.jsp" name="editForm" path="/editAction"
scope="session" type="userval.EditAction" validate="true" />
</action-mappings>
<message-resources parameter="ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
</struts-config>

--validation.xml文件内容:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
<form-validation>

<formset>
<form name="/editForm ">
<field property="name"
depends="required,mask,minlength">
<arg0 key="editForm.name"/>
<arg1 name="minlength" key="${var:minlength}" resource="false"/>
<var>
<var-name>mask</var-name>
<var-value>^\w+$</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
</field>
<field property="pwd1" depends="required,mask">
<arg0 key="editForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
<field property="pwd2" depends="required,mask">
<arg0 key="editForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
<field property="address" depends="required ">
<arg0 key="editForm.address"/>
</field>
</form>
</formset>
</form-validation>

--index.jsp文件内容:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<html:html locale="true">
<head>
<title>index</title>
</head>
<body>
<html:errors/>
<!--html:form action="/editAction.do" method="POST"-->
<html:form action="/editAction.do" onsubmit="return validateEditForm(this);">

<bean:message key="editForm.address"/>
<html:text property="address"/>
<br>
<bean:message key="editForm.name"/>
<html:text property="name"/>
<br>
<bean:message key="editForm.password"/>
<html:password property="pwd1"/>
<br>
<bean:message key="editForm.password"/>
<html:password property="pwd2"/>
<br>
<html:submit property="submit" value="Submit"/><br>
<html:reset value ="Reset"/>
</html:form>
</body>
</html:html>

<html:javascript formName="editForm"
dynamicJavascript="true"
staticJavascript="false"/>
<script language="Javascript1.1" src="staticJavascript.jsp"></script>

--EditForm.java文件内容:
package userval;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class EditForm
extends ActionForm
{
private String address;
private String name;
private String pwd1;
private String pwd2;
public String getAddress()
{
return address;
}

public void setAddress(String address)
{
this.address = address;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public String getPwd1()
{
return pwd1;
}

public void setPwd1(String pwd1)
{
this.pwd1 = pwd1;
}

public String getPwd2()
{
return pwd2;
}

public void setPwd2(String pwd2)
{
this.pwd2 = pwd2;
}

// public ActionErrors validate(ActionMapping actionMapping,
// HttpServletRequest httpServletRequest)
// {
/**@todo: finish this method, this is just the skeleton.*/
// return null;
// }

public void reset(ActionMapping actionMapping,
HttpServletRequest httpServletRequest)
{
address = null;
name = null;
pwd1 = null;
pwd2 = null;
}
}
--EditAction.java文件内容:
package userval;

import java.util.Locale;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.MessageResources;

public class EditAction
extends Action
{
//private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
{

/**@todo: complete the business logic here, this is just a skeleton.*/
// EditForm editForm = (EditForm) actionForm;
// throw new java.lang.UnsupportedOperationException(
//"Method perform() not yet implemented.");
return actionMapping.findForward("success");
}
}

--ApplicationResources.properties文件内容:
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.

errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.

errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.

editForm.name= name.
editForm.password= password.
editForm.address= address

现在程序可以运行,但是就是错误的输入数据不能提示错误出来
环境JBX+WebLogic8.1 环境配置绝对没有问题

搞了好几天,就是不能正常工作,跪求各位朋友解决
QQ:45214493




Java开发规范

话题树型展开
人气 标题 作者 字数 发贴时间
1567 struts表单检测不能显示数据错误??? mybillliu 6745 2004-08-02 16:29
1062 Re:struts表单检测不能显示数据错误??? mybillliu 4 2004-08-04 10:23

reply to postflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923