struts2.1 xml 验证的错误信息总重复显示, why? 急!
我采用的技术是:struts2.1 + hibernate 3.3 +spring 3.0.
我有一个用户登录界面需要验证用户名是否为空。
假如我没有输入用户名, 点击登录, 则进入错误提示界面: 用户名不能为空。
然后我返回登录界面, 仍然不输入用户名, 点击登录, 则进入错误提示界面: 显示2行 用户名不能为空。
我重复N次, 则显示N行: 用户名不能为空。
error.jsp内容:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<s:fielderror/>
has error
验证文件UsersAction-login-validation.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.3//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd">
<validators>
<field name="uname">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>user name cannot be null</message>
</field-validator>
</field>
</validators>
web.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
structs.xml内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"></constant>
<package name="com.login" extends="struts-default">
<action name="login" class="UsersAction" method="login">
<result name="success">/index.jsp</result>
<result name="input">/error.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
applicationContext.xml内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.sprin