testAction

作者在 2010-12-23 08:40:07 发布以下内容
1.testAction
-------------------------------------------------------------------
package action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import data.BookDao;
public class TestAction extends ActionSupport {
 
 static private List<BookDao> books = new ArrayList<BookDao>();
 
 static {
  BookDao book1 = new BookDao();
  BookDao book2 = new BookDao();
  BookDao book3 = new BookDao();
  
  book1.setBookID("001");
  book1.setBookName("book001");
  book2.setBookID("002");
  book2.setBookName("book002");
  book3.setBookID("003");
  book3.setBookName("book003");
  
  books.add(book1);
  books.add(book2);
  books.add(book3);
 }
 
 public String execute() {
  ActionContext ctx = ActionContext.getContext();
  Map session = ctx.getSession();
  session.put("selectList", books);
  return SUCCESS; 
 }
 public static List<BookDao> getBooks() {
  return books;
 }
 public static void setBooks(List<BookDao> books) {
  TestAction.books = books;
 }
}
------------------------------------------------------
 
2.test2Action
------------------------------------------------------
package action;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class Test2Action extends ActionSupport {
 
 final String HTTP_REQUEST = org.apache.struts2.StrutsStatics.HTTP_REQUEST;
 
 public String execute() {
  ActionContext ctx = ActionContext.getContext();
  HttpServletRequest req = (HttpServletRequest) ctx.get(HTTP_REQUEST);
  Map session = ctx.getSession();
  session.put("key", req.getParameter("incision1"));
  return SUCCESS; 
 }
}
------------------------------------------------------------------
 
3.test.jsp
------------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'test.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
  </head>
 
  <body>
    <s:form action="testAction">
    <s:submit>OK</s:submit>
    </s:form>
  </body>
</html>
---------------------------------------------------------------------
 
4.testResult.jsp
-----------------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'testResult.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
  </head>
 
  <body>
    <body>
    <s:form action="test2Action">
     <s:select name="incision1" list="books" listKey="bookID" listValue="bookName"
         headerKey="" headerValue=" - " multiple="false"  theme="simple">
        </s:select>
        <s:submit>kk</s:submit>
    </s:form>
  </body>
</html>
----------------------------------------------------------------------------
 
5.test2Result.jsp
--------------------------------------------------------------------------

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'test2Result.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

  </head>
 
  <body>
  !!!
       ${sessionScope.key}
       !!!
  </body>
</html>
---------------------------------------------------------------------------

 
J2EE | 阅读 1105 次
文章评论,共0条
游客请输入验证码