狂淘

          www.kuangtao.net

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            6 隨筆 :: 185 文章 :: 68 評論 :: 0 Trackbacks
          1.index.jsp
                 <s:form action="HelloChina.action" method="post">
                      Name: <s:textfield name="name" value=""/>
                      <s:submit />
                  </s:form>
          2.HelloChina

          package com.xushi.bll;

          import java.util.Map;

          import javax.servlet.http.HttpServletRequest;

          import org.apache.struts2.ServletActionContext;

          import com.opensymphony.xwork2.ActionContext;
          import com.opensymphony.xwork2.ActionSupport;

          public class HelloChina extends ActionSupport {
            private String name;
              
               public String getName() {
                   return name;
               }
              
               public void setName(String name) {
                   this.name = name;
               }
               public String execute() {
               HttpServletRequest request = ServletActionContext.getRequest();
                request.getSession().setAttribute("abc", request.getParameter("name"));
          //Map map=ActionContext.getContext().getSession();
            //    map.put("abc", request.getParameter("name"));
                   return "test";
               }
          }

          3.test.jsp
          <%@ page language="java" contentType="text/html; charset=UTF-8"
              pageEncoding="UTF-8"%>
              <%@ taglib prefix="s" uri="/struts-tags" %>
          <!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>
          <s:property value="#session.abc" />
          </body>
          </html>

          4.struts.xml
          <action name="HelloChina" class="com.xushi.bll.HelloChina">
             <result name="test">/pack/test.jsp</result>  
            </action>

          posted on 2009-10-21 09:10 狂淘 閱讀(1173) 評論(0)  編輯  收藏 所屬分類: struts2.0 spring hiberate
          主站蜘蛛池模板: 西和县| 寿光市| 顺义区| 逊克县| 织金县| 涪陵区| 民丰县| 七台河市| 尉氏县| 正宁县| 石嘴山市| 湖南省| 甘谷县| 香港 | 河源市| 丹阳市| 乐平市| 新巴尔虎左旗| 大埔县| 南城县| 延吉市| 沧源| 沙洋县| 本溪市| 长寿区| 南靖县| 兰州市| 台江县| 达拉特旗| 丹棱县| 泰来县| 广东省| 沙田区| 灵璧县| 三台县| 民乐县| 香河县| 宜都市| 临清市| 揭东县| 博罗县|