狂淘

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 狂淘 阅读(1160) 评论(0)  编辑  收藏 所属分类: struts2.0 spring hiberate

只有注册用户登录后才能发表评论。


网站导航: