JSP请求页面(传参)

JSP请求页面(传参) 
Html代码   收藏代码
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2.   
  3. <%  
  4. String path = request.getContextPath();  
  5. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  6. %>  
  7.   
  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  9. <html>  
  10.   <head>  
  11.     <base href="<%=basePath%>">  
  12.       
  13.     <title>My JSP 'index.jsp' starting page</title>  
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.     <!-- 
  20.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  21.     -->  
  22.   </head>  
  23.     
  24.   <body>  
  25.     向结果传参数  
  26.     <ol>  
  27.         <li><a href="user/user?type=1">传参数</a></li>  
  28.     </ol>  
  29.   </body>  
  30. </html>  
 



struts.xml的配置(接收jsp传来的参数) 
Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  5.   
  6. <struts>  
  7. <constant name="struts.i18n.encoding" value="UTF-8"></constant>  
  8. <constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>  
  9.     <package name="user" extends="struts-default" namespace="/user">  
  10.         <action name="user" class="com.lbx.action.UserAction">  
  11.             <result type="redirect">/success.jsp?t=${type}</result>  
  12.         </action>  
  13.     </package>  
  14.       
  15. </struts>  
  
Action的处理为参数体统set和get方法 
Java代码   收藏代码
  1. package com.lbx.action;  
  2.   
  3.   
  4. import com.opensymphony.xwork2.ActionSupport;  
  5.   
  6. @SuppressWarnings("serial")  
  7. public class UserAction extends ActionSupport{  
  8.     private int type;  
  9.       
  10.     public int getType() {  
  11.         return type;  
  12.     }  
  13.     public void setType(int type) {  
  14.         this.type = type;  
  15.     }  
  16.     @Override  
  17.     public String execute() throws Exception {  
  18.         System.out.println("UserAction.execute()");  
  19.         return SUCCESS;  
  20.     }  
  21.       
  22.       
  23. }  
  



success.jsp页面(读出传过来的值) 
Html代码   收藏代码
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%@taglib prefix="s" uri="/struts-tags"%>  
  3. <%  
  4. String path = request.getContextPath();  
  5. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  6. %>  
  7.   
  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  9. <html>  
  10.   <head>  
  11.     <base href="<%=basePath%>">  
  12.       
  13.     <title>My JSP 'success.jsp' starting page</title>  
  14.       
  15.     <meta http-equiv="pragma" content="no-cache">  
  16.     <meta http-equiv="cache-control" content="no-cache">  
  17.     <meta http-equiv="expires" content="0">      
  18.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  19.     <meta http-equiv="description" content="This is my page">  
  20.     <!-- 
  21.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  22.     -->  
  23.   
  24.   </head>  
  25.     
  26.   <body>  
  27.     User Success!  
  28.     from valuestack: <s:property value="t"/><br/>  
  29.     from actioncontext: <s:property value="#parameters.t"/>  
  30.     <s:debug></s:debug>  
  31.   </body>  
  32. </html>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值