本文标签:JSP页面传值
这周在调支付宝的接口 。期间需要把我方程序处理后的参数(交易金额)按照规定的格式传递给支付宝的接口 。因为中途要设计到我方程序对一些数据的处理,所以并不方便直接传值过去 。思来想去,决定先把我方的数据提交给webwork的Action进行处理,也就是对数据库进行操作;然后把交易金额以及支付宝接口需要的其他参数一并传递给一个JSP页面,并让这个JSP页面在把action直接指向支付宝的网关接口,注意:中间过程中这个JSP页面时不显示出来的 。为此,做了如下测试:建立两个JSP页面传值,tes1.jsp和test2.jsp 。代码如下: - <%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%>
- <%
Stringpath=request.getContextPath(); StringbasePath=request.getScheme()+"://"+request.getServerName() +":"+request.getServerPort()+path+"/"; %> > <html> <head> <basehrefbasehref="<%=basePath%>"> <title>MyJSPtest1.jspstartingpage< SPAN>title> <metahttp-equivmetahttp-equiv="pragma"content="no-cache"> <metahttp-equivmetahttp-equiv="cache-control"content="no-cache"> <metahttp-equivmetahttp-equiv="expires"content="0"> <metahttp-equivmetahttp-equiv="keywords"content="keyword1,keyword2,keyword3"> <metahttp-equivmetahttp-equiv="description"content="Thisismypage"> <metahttp_equivmetahttp_equiv="refresh"content="5"> <scriptlanguagescriptlanguage="javascript"type="text/javascript"> functionexecute(){ varobj=document.getElementById("name"); document.form1.action="alipay/test2.jsp?param="+obj.value; document.form1.submit(); } < SPAN>script> < SPAN>head> <bodyonloadbodyonload="execute();"> <formnameformname="form1"method="post"> <table> <tr> <td> 测试JSP页面传值<inputtypeinputtype="text"id="username"value="luodada"> < SPAN>td> < SPAN>tr> < SPAN>table> < SPAN>form> < SPAN>body> < SPAN>html>
tset2.jsp的代码如下: - <%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%>
- <%
- Stringpath=request.getContextPath();
- StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- >
- <html>
- <head>
- <basehrefbasehref="<%=basePath%>">
- <title>MyJSPtest2.jspstartingpage< SPAN>title>
- <metahttp-equivmetahttp-equiv="pragma"content="no-cache">
- <metahttp-equivmetahttp-equiv="cache-control"content="no-cache">
- <metahttp-equivmetahttp-equiv="expires"content="0">
- <metahttp-equivmetahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
- <metahttp-equivmetahttp-equiv="description"content="Thisismypage">
-
- < SPAN>head>
- <body>
- <%
- Stringvalue=request.getParameter("param");
- out.print("从test1.jsp传递过来的值是"+value);
- %>
- < SPAN>body>
- < SPAN>html>
具体思路如下:
在JSP页面传值test1.jsp中,通过JavaScript把文本框中的值获取出来,,使test1.jsp在加载进来的时候马上执行页面跳转;
在JSP页面传值test2.jsp中通过request.getParameter("参数名称");来获取test1.jsp传递过来的值即可 。
|