<?xml version="1.0" encoding="GBK"?> <project name="struts" basedir="." default=""> <property name="dist" value="classes"/> <property name="src" value="src"/> <path id="classpath"> <fileset dir="lib"> <include name="*.jar"/> </fileset> <pathelement path="${dist}"/> </path> <target name="compile" description="Compile all source code"> <delete dir="${dist}"/> <mkdir dir="${dist}"/> <copy todir="${dist}"> <fileset dir="${src}"> <exclude name="**/*.java"/> </fileset> </copy> <javac destdir="classes" debug="true" includeantruntime="yes" deprecation="false" optimize="false" failonerror="true"> <src path="${src}"/> <classpath refid="classpath"/> </javac> </target> </project>
<?xml version="1.0" encoding="GBK"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <! - define the core of Filter Struts 2 -> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <! - let Struts core Filter 2 intercept all requests -> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
XWork. default .invalid.fieldvalue = {0} field type conversion failures!
xwork.default.invalid.fieldvalue={0}\u5b57\u6bb5\u7c7b\u578b\u8f6c\u6362\u5931\u8d25\uff01
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="mess"/> <constant name="struts.i18n.encoding" value="GBK"/> <package name="conversion" extends="struts-default"> <action name="login" class="org.crazyit.app.action.LoginAction"> <result>/WEB-INF/content/welcome.jsp</result> <result name="error">/WEB-INF/content/welcome.jsp</result> <result name="input">/WEB-INF/content/ognlInput.jsp</result> </action> <action name="*"> <result>/WEB-INF/content/{1}.jsp</result> </action> </package> </struts>
org.crazyit.app.domain.User = org.crazyit.app.converter.UserConverter
<% - Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> author yeeku.H.lee kongyeeku @ 163 .com which version of the 1.0 for Amsterdam Copyright (the C), 20012016 , yeekuHLee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <%@taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <Title> type conversion error handling </ title> <s:head/> </head> <body> <s:fielderror /> <H3> type conversion error handling </ h3> <s:form action="login"> <s:iterator value="{0, 1, 2}" status="stat"> <! - only one request parameter -> <S: TextField name = "Users" label = "% {# stat.index} The first user information" /> </s:iterator> <tr> <td colspan="2"><s:submit value="转换" theme="simple"/> <s:reset value="重填" theme="simple"/></td> </tr> </s:form> </body> </html>
<% - Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> author yeeku.H.lee kongyeeku @ 163 .com which version of the 1.0 for Amsterdam Copyright (the C), 20012016 , yeekuHLee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <%@taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <Title> type conversion error handling </ title> <s:head/> </head> <body> <s:fielderror /> <H3> type conversion error handling </ h3> <s:form action="login"> <s:iterator value="{0, 1, 2}" status="stat"> <! - this will in turn generate a plurality of request parameters -> <S: TextField name = "Users [% {# stat.index}]" label = "% {# stat.index} The first user information" /> </s:iterator> <tr> <td colspan="2"><s:submit value="转换" theme="simple"/> <s:reset value="重填" theme="simple"/></td> </tr> </s:form> </body> </html>
<% - Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> author yeeku.H.lee kongyeeku @ 163 .com which version of the 1.0 for Amsterdam Copyright (the C), 20012016 , yeekuHLee This program is protected by copyright laws. Program Name: Date: --%> <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %> <%@taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <Title> conversions </ title> </head> <body> conversion result ! a <s:iterator value="users" status="status"> 用户<s:property value="%{#status.index}"/>的用户名:<s:property value="name"/><br/> 用户<s:property value="%{#status.index}"/>的密码:<s:property value="pass"/><br/> </s:iterator> </body> </html>
XWork. default .invalid.fieldvalue = {0} field type conversion failures!
xwork.default.invalid.fieldvalue={0}\u5b57\u6bb5\u7c7b\u578b\u8f6c\u6362\u5931\u8d25\uff01
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="mess"/> <constant name="struts.i18n.encoding" value="GBK"/> <package name="conversion" extends="struts-default"> <action name="login" class="org.crazyit.app.action.LoginAction"> <result>/WEB-INF/content/welcome.jsp</result> <result name="error">/WEB-INF/content/welcome.jsp</result> <result name="input">/WEB-INF/content/ognlInput.jsp</result> </action> <action name="*"> <result>/WEB-INF/content/{1}.jsp</result> </action> </package> </struts>
org.crazyit.app.domain.User = org.crazyit.app.converter.UserConverter
package org.crazyit.app.action; import com.opensymphony.xwork2.Action; import java.util.Date; import java.util.List; import com.opensymphony.xwork2.ActionSupport; import org.crazyit.app.domain. * ; / ** * Description: * <br/> website: <a href=" http://www.crazyit.org "> crazy Java league </a> * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * Author YeekuHLee kongyeeku163com * @version 1.0 */ public class LoginAction extends ActionSupport { private List<User> users; // users的setter和getter方法 public void setUsers(List<User> users) { this.users = users; } public List<User> getUsers() { return users; } }
package org.crazyit.app.converter; import java.util.Map; import org.apache.struts2.util.*; import org.crazyit.app.domain. * ; / ** * Description: * <br/> website: <a href=" http://www.crazyit.org "> crazy Java league </a> * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * Author YeekuHLee kongyeeku163com * @version 1.0 */ public class UserConverter extends StrutsTypeConverter { // achieve a string type to convert into a composite method of the type public Object ConvertFromString (context the Map , String[] values , Class toClass) { // Create a User instance User User = new new User (); // only the first array element processing request parameter array, // and the comma character string into two strings String [] userValues = values [ 0] .split ( "," ); // for the User assignment example user.setName (userValues [0 ]); user.setPass (userValues [ . 1 ]); // Returns converted instance of User return User; } // implementation will convert to a composite type of method of type string public String convertToString (the Map context, Object O) { // The value to be converted to a User instance cast User = User (User) O; return "<" + user.getName () + "," + user.getPass() + ">"; } }
package org.crazyit.app.domain; /** * Description: * <br/> website: <a href=" http://www.crazyit.org "> crazy Java league </a> * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * Author YeekuHLee kongyeeku163com * @version 1.0 */ public class User { private String name; private String pass; // setter and getter method name of public void setName (String name) { this.name = name; } public String getName() { return this.name; } // setter and getter methods pass a public void SETPASS (String pass) { this.pass = pass; } public String getPass() { return this.pass; } }