第13講 struts2的Action的生命週期
阿新 • • 發佈:2018-11-11
1複製HeadFirstStruts2chapter02-05,改名:HeadFirstStruts2chapter02-06,修改web project settings ,
2建立HelloAction,繼承ActionSupport,刪除其他的Action,
package com.cruise.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloAction extends ActionSupport{
public
}
@Override
public String execute() throws Exception {
System.out.println(this);
return
}
}
3修改struts.xml檔案,修改success.jsp 檔案,刪除其他的jsp檔案
struts.xml檔案檔案如下:
<?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>
<package name="manage"
<action name="hello" class="com.cruise.action.HelloAction" >
<result name="success">success.jsp</result>
</action>
</package>
</struts>
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>Insert title here</title>
</head>
<body>
OK!!
</body>
</html>
4測試,http://localhost:8080/HeadFirstStruts2chapter02_06/hello
結論每次呼叫都建立一個新的Action例項,