struts2标签:在struts2-core的JAR包中META-INF下的struts-tags.tld
<%@ taglib prefix="s" uri="/struts-tags"%>这里的/struts-tags可以在struts-tags.tld中找到。
LoginAction继承ActionSupport后,ActionSupport有一个自动的validate验证,source-override....--validate勾上
private void validate()
{
if(null == this.getUsername() || "".equals(this.getUsername().trim()))
{
this.addFieldError("username","username required");
}
}
则在struts.xml中还要写<result name="input">login2.jsp</result>
public String execute() throws Exception
{
if("Hello".equals(this.getUsername().trim()) && "password".equals(this.getPassword().trim()))
{
return "success";
}
else
{
this.addFieldError("username","username or password error");
return "falure";
}
}
则在struts.xml中还要写<result name="falure">login2.jsp</result>
getAttibute(...)的是一个object类型
改变ISO-8859-1的默认值:window-property- Myeclipse- Files and Editors--JSP
login2.jsp中point,username,age,date四个field
新建一个com.test.bean--Point类: private int x, private int y;
ognl类下面的TypeConverter.class--convertValue(.....)
https://xwork.dev.java.net/source/browse/ognl/在这里进行check out,要下载一个cvs客户端(wincvs)--admin--第一个,连接的时候 admin-第二个.
http://www.opensymphony.com/ognl/cvs.action左边的JavaDoc找到TypeConverter这个接口(最后一个)
新建一个com.test.converter包--PointConverter(继承defaultTypeConverter这个类)-source-override(...)重写第一个
PointConverter.java:
@override
public Object converterValue(Map context, Object value, Class toType)
{
if(Point.class == toType)
{
Point point = new Point();
String[] str = (String[])value;
String[] paramValues = str[0].split(",");
int x = Integer.parseInt(paramValues[0]);
int y = Integer.parseInt(paramValues[1]);
point.setX(x);
point.setY(y);
return point;
}
if(String.class == toType)
{
Point point = (Point)value;
int x = point.getX(x);
int x = point.getY(y);
String result = "[x="+x+" ,y="+y+"]";
return result;
}
return null;
}
com.test.Action--PointAction(extends ActionSupport)
execute()..方法中return SUCCESS(看文档,表成功)
com.test.action下新建一个file:File name:PointAction-conversion.properties(-conversion.properties是固定永远不变的)
PointAction你对哪个Action里面的属性进行类型转换就写哪个Action.且这个file必须与这个Action建在同一个目录下。即对PointAction这个类下的一些属性进行类型转换
output.jsp
<body>
point:<s:property value="point"/>
age:<s:property value="age"/>
username:<s:property value="username"/>
date:<s:property value="date"/>