HelloWorld的几种实现方式
/20170913_chr_hellochr/src/nuc/sw/action/Action.java
package nuc.sw.action;
import com.opensymphony.xwork2.ActionSupport;
public class Action extends ActionSupport {
public String execute () {
return "success" ;
}
}
/20170913_chr_hellochr/src/nuc/sw/action/HelloActionOne.java
package nuc.sw.action;
public class HelloActionOne {
public String execute () {
return "success" ;
}
}
/20170913_chr_hellochr/src/nuc/sw/action/HelloActionTwo.java
package nuc.sw.action;
import com.opensymphony.xwork2.Action;
public class HelloActionTwo implements Action {
@Override
public String execute () throws Exception {
return SUCCESS;
}
}
/20170913_chr_hellochr/src/struts.xml
<?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 >
<package name ="helloPackage" namespace ="/" extends ="struts-default" >
<action name ="helloOne" class ="nuc.sw.action.HelloActionOne" >
<result name ="success" >
/success.jsp
</result >
</action >
<action name ="helloTwo" class ="nuc.sw.action.HelloActionTwo" >
<result name ="success" >
/success2.jsp
</result >
</action >
</package >
</struts >
/20170913_chr_hellochr/WebContent/success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head >
<meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
<title > 第一个欢迎页</title >
</head >
<body >
hello struts2_one!!!
</body >
</html >
/20170913_chr_hellochr/WebContent/success2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head >
<meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
<title > 第二个欢迎页</title >
</head >
<body >
hello struts2_two!!!
</body >
</html >