1. Configure the Java JDK version. property to configure the version in Java Compier.
2, to create useraction.
public class Useraction extends Actionsupport {
private String name;
private int age;
Public String Add () {
System.out.println ("name=" + name);
System.out.println ("age=" + age);
return SUCCESS;
}
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
public int getage () {
return age;
}
public void Setage (int.) {
This.age = age;
}
3, the same as the last study to configure struts,
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache software foundation//dtd Struts Configuration 2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >
<struts>
<constant name= "Struts.devmode" value= "true"/>
<package name= "user" extends= "struts-default" namespace= "/user" >
<action name= "user" class= "com.bjsxt.struts2.user.action.UserAction" >
<result>/user_add_success.jsp</result>
</action>
</package>
</struts>
4, Webroot
<?xml version= "1.0" encoding= "GB18030"?>
<%@ page language= "java" contenttype= "text/html; charset=gb18030 "
pageencoding= "GB18030"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb18030 "/>
<base href= "<%=basepath%>"/>
<title>insert title here</title>
<body>
Use the Action property to receive parameters <a href= "User/user!add?name=a&age=8" > Add Users </a>
</body>
Here we use how to use the Action property to accept parameters.
5. The user added success is shown here.
<?xml version= "1.0" encoding= "GB18030"?>
<%@ page language= "java" contenttype= "text/html; charset=gb18030 "
pageencoding= "GB18030"%>
<% @taglib uri= "/struts-tags" prefix= "s"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb18030 "/>
<title>insert title here</title>
<body>
Add User Success! haha haha haha haha ha ha ha ha haha haha hahaha!!!!!!!!!!!!!!!!!!!
</body>
Learn to use the Action property to accept parameters