狂淘

          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 狂淘 閱讀(1174) 評論(0)  編輯  收藏 所屬分類: struts2.0 spring hiberate
          主站蜘蛛池模板: 东方市| 灵武市| 梅河口市| 光山县| 横峰县| 尚义县| 高密市| 洛浦县| 虞城县| 辽中县| 定陶县| 合水县| 崇文区| 高陵县| 陇川县| 赤水市| 雷波县| 嘉禾县| 林州市| 夏邑县| 阿坝| 陆丰市| 惠安县| 晋州市| 涪陵区| 汉川市| 金山区| 望谟县| 巴彦县| 宝鸡市| 乾安县| 涟源市| 阿拉善盟| 周口市| 独山县| 新营市| 曲阳县| 龙川县| 钟山县| 博罗县| 荥经县|