JSP如何实现页面传值
这篇文章将为大家详细讲解有关JSP如何实现页面传值,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
创新互联公司是一家专业提供肃宁企业网站建设,专注与网站设计、成都网站设计、H5技术、小程序制作等业务。10年已为肃宁众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
这周在调支付宝的接口。期间需要把我方程序处理后的参数(交易金额)按照规定的格式传递给支付宝的接口。因为中途要设计到我方程序对一些数据的处理,所以并不方便直接传值过去。思来想去,决定先把我方的数据提交给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+"/";%>
>
<basehrefbasehref="<%=basepath%>">
</strong>MyJSP'test1.jsp'startingpage<strong>title></strong> </p></li><li><p><strong><</strong>metahttp-equiv<strong>metahttp-equiv</strong>="pragma"content="no-cache"<strong>></strong> </p></li><li><p><strong><</strong>metahttp-equiv<strong>metahttp-equiv</strong>="cache-control"content="no-cache"<strong>></strong> </p></li><li><p><strong><</strong>metahttp-equiv<strong>metahttp-equiv</strong>="expires"content="0"<strong>></strong> </p></li><li><p><strong><</strong>metahttp-equiv<strong>metahttp-equiv</strong>="keywords"content="keyword1,keyword2,keyword3"<strong>></strong> </p></li><li><p><strong><</strong>metahttp-equiv<strong>metahttp-equiv</strong>="description"content="Thisismypage"<strong>></strong> </p></li><li><p><strong><</strong>metahttp_equiv<strong>metahttp_equiv</strong>="refresh"content="5"<strong>></strong> </p></li><li><p> </p></li><li><p><strong><</strong>scriptlanguage<strong>scriptlanguage</strong>="javascript"type="text/javascript"<strong>></strong> </p></li><li><p>functionexecute(){ </p></li><li><p>varobj=document.getElementById("name"); </p></li><li><p>document.form1.action="alipay/test2.jsp?param="+obj.value; </p></li><li><p>document.form1.submit(); </p></li><li><p>} </p></li><li><p><strong>script></strong> </p></li><li><p><strong>head></strong> </p></li><li><p><strong><</strong>bodyonload<strong>bodyonload</strong>="execute();"<strong>></strong> </p></li><li><p><strong><</strong>formname<strong>formname</strong>="form1"method="post"<strong>></strong> </p></li><li><p><strong><table></strong> </p></li><li><p><strong><tr></strong> </p></li><li><p><strong><td></strong> </p></li><li><p>测试JSP页面传值<strong><</strong>inputtype<strong>inputtype</strong>="text"id="username"value="luodada"<strong>></strong> </p></li><li><p><strong>td></strong> </p></li><li><p><strong>tr></strong> </p></li><li><p><strong>table></strong> </p></li><li><p><strong>form></strong> </p></li><li><p><strong>body></strong> </p></li><li><p><strong>html></strong> </p></li></ol></pre><p>tset2.jsp的代码如下:</p><pre><%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%> <% Stringpath=request.getContextPath(); StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> > <html> <head> <basehrefbasehref=""> <title>MyJSP'test2.jsp'startingpagetitle> <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"> head> <body> <% Stringvalue=request.getParameter("param"); out.print("从test1.jsp传递过来的值是"+value); %> body> html></pre><p>具体思路如下:</p><p>在JSP页面传值test1.jsp中,通过JavaScript把文本框中的值获取出来,,使test1.jsp在加载进来的时候马上执行页面跳转;</p><p>在JSP页面传值test2.jsp中通过request.getParameter("参数名称");来获取test1.jsp传递过来的值即可。</p><p>关于“JSP如何实现页面传值”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。</p> <br> 文章题目:JSP如何实现页面传值 <br> 文章链接:<a href="http://scpengxi.com/article/gccdic.html">http://scpengxi.com/article/gccdic.html</a> </div> </div> <div class="contentr fr"> <h3>其他资讯</h3> <ul> <li> <a href="/article/ddgcidh.html">mysql怎么更新列值 mysql更新语句</a> </li><li> <a href="/article/ddgcise.html">服务器的安全保密协议 服务器的安全防护</a> </li><li> <a href="/article/ddgcshi.html">linux查命令源码 linux查看源文件</a> </li><li> <a href="/article/ddgcidj.html">mysql怎么查找外键 mysql查询表的外键</a> </li><li> <a href="/article/ddgcioh.html">智能聊天小学生 小学生wwe</a> </li> </ul> </div> </div> </div> <!--底部--> <footer> <div class="foot"> <div class="container"> <h1>蓬溪谬誉钊凯建站您身边的网站制作服务商</h1> <div class="foot1"> <ul> <li> <dl><i class="iconfont"></i><b>地址ADDRESS</b></dl> <p>四川-成都青羊区太升南路288号<br> 锦天国际A座10楼 </p> </li> <li> <dl><i class="iconfont"></i><b>电话/TEL</b></dl> <p><a href="tel:02886922220" target="_blank">028 86922220</a> (工作日)<br> <a href="tel:18980820575" target="_blank">1898082 0575</a> ( 7x24 ) </p> </li> <li> <dl><i class="iconfont"></i><b>QQ咨询</b></dl> <p> 244261566 (售前)<br> 631063699 (售后) </p> </li> <li> <dl><i class="iconfont"></i><b>邮箱/E: mail</b></dl> <p> service@cdcxhl.com (业务)<br> hr@cdcxhl.com (求职) </p> </li> </ul> </div> <div class="link"> 友情链接: <a href="http://www.4006tel.net/mobile/" title="手机软件开发" target="_blank">手机软件开发</a> <a href="http://www.cqcxhl.com/" title="重庆网站建设公司" target="_blank">重庆网站建设公司</a> <a href="https://www.cdcxhl.com/google.html" title="Google外贸推广" target="_blank">Google外贸推广</a> <a href="https://www.cdcxhl.com/shop.html" title="商城网站建设" target="_blank">商城网站建设</a> <a href="http://www.scyanting.com/" title="盐亭做网站" target="_blank">盐亭做网站</a> <a href="https://www.cdxwcx.com/wangzhan/app.html" title="手机app" target="_blank">手机app</a> <a href="http://m.cdxwcx.com/xibuxinxi.html" title="西部信息中心" target="_blank">西部信息中心</a> <a href="http://www.tpbzx.cn/" title="www.tpbzx.cn" target="_blank">www.tpbzx.cn</a> <a href="http://www.cdxwcx.cn/tuoguan/nanchong.html" title="南充主机托管" target="_blank">南充主机托管</a> <a href="http://chengdu.cdcxhl.com/xcx/" title="成都微信小程序开发" target="_blank">成都微信小程序开发</a> </div> </div> </div> <div class="copy container"> Copyright © 2025 All Rights Reserved. 成都谬誉钊凯广告有限公司 版权所有 <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备2024104775号-15</a> [原创设计,独立版权。未经许可.不得拷贝或镜像]<br> <a href="http://www.kswsj.cn/" target="_blank">网站营销推广</a> | <a href="https://www.cdcxhl.com/pinpai.html" target="_blank">品牌网站设计</a> | <a href="http://www.cdweb.net/" target="_blank">自适应网站制作</a> | <a href="http://cdkjz.cn/wangzhan/pinpai/" target="_blank">品牌网站制作</a> | <a href="http://chengdu.cdxwcx.cn/" target="_blank">成都网站制作</a> | <a href="https://www.cdcxhl.com/cloud/" target="_blank">云服务器</a> | <a href="https://www.cdcxhl.com/weihu/abazhou.html" target="_blank">蓬溪网站维护</a> | (蓬溪网站制作QQ : 631063699 )</div> </footer> <!--在线咨询--> <div class="fot"> <ul> <li> <a href="mqqwpa://im/chat?chat_type=wpa&uin=532337155&version=1&src_type=web&web_src=oicqzone.com" target="_blank"> <img src="/Public/Home/img/fot1.png" alt="建站咨询"> <p>在线咨询</p> </a> </li> <li> <a href="tel:18980820575" target="_blank"> <img src="/Public/Home/img/fot2.png" alt="建站电话"> <p>拨打电话</p> </a> </li> </ul> </div> </body> </html> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>