狂淘

          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 狂淘 閱讀(1167) 評論(0)  編輯  收藏 所屬分類: struts2.0 spring hiberate
          主站蜘蛛池模板: 江口县| 吴川市| 昆明市| 监利县| 全南县| 普格县| 清徐县| 翁牛特旗| 钦州市| 陆河县| 梁平县| 从江县| 门头沟区| 太原市| 洛浦县| 平乐县| 葫芦岛市| 木里| 连平县| 定州市| 革吉县| 兰考县| 中超| 沈丘县| 玛曲县| 岳阳市| 彭阳县| 浠水县| 堆龙德庆县| 志丹县| 江华| 奉贤区| 兴安县| 都匀市| 华宁县| 荆门市| 汨罗市| 鞍山市| 太湖县| 延寿县| 大城县|