JSP如何实现页面传值

这篇文章将为大家详细讲解有关JSP如何实现页面传值,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

创新互联公司是一家专业提供肃宁企业网站建设,专注与网站设计、成都网站设计H5技术、小程序制作等业务。10年已为肃宁众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。

这周在调支付宝的接口。期间需要把我方程序处理后的参数(交易金额)按照规定的格式传递给支付宝的接口。因为中途要设计到我方程序对一些数据的处理,所以并不方便直接传值过去。思来想去,决定先把我方的数据提交给webwork的Action进行处理,也就是对数据库进行操作;然后把交易金额以及支付宝接口需要的其他参数一并传递给一个JSP页面,并让这个JSP页面在把action直接指向支付宝的网关接口,注意:中间过程中这个JSP页面时不显示出来的。为此,做了如下测试:建立两个JSP页面传值,tes1.jsp和test2.jsp。代码如下:

  1. <%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%> 

  2. <%  

  3. Stringpath=request.getContextPath();  

  4. StringbasePath=request.getScheme()+"://"+request.getServerName()
    +":"+request.getServerPort()+path+"/";  

  5. %> 

  6. > 

  7.  

  8.  

  9. <basehrefbasehref="<%=basepath%>"> 

  10.  

  11. </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> 链接URL:<a href="http://bzwzjz.com/article/gccdic.html">http://bzwzjz.com/article/gccdic.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/doohigd.html">JAVA填写地址代码 java位置代码</a> </li><li> <a href="/article/doohigh.html">c语言main函数意义 c语言中main函数是什么意思</a> </li><li> <a href="/article/doohise.html">数据库php全屏编辑 数据库php全屏编辑</a> </li><li> <a href="/article/doohiej.html">linux查表空间命令 linux查询硬盘空间命令</a> </li><li> <a href="/article/doohigc.html">vb与vb.net vb与vbnet</a> </li> </ul> </div> </div> <div class="footer2"> Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号 <br />友情链接: <a href="http://chengdu.cdcxhl.cn/" target="_blank">成都网站设计 </a><a href="https://www.cdxwcx.com/wangzhan/pinpai.html" target="_blank">高端品牌网站建设 </a><a href="https://www.cdcxhl.com/" target="_blank">成都网站制作 </a><a href="http://chengdu.cdcxhl.cn/seo/" target="_blank">营销网站建设 </a><a href="http://www.kswcd.com/" target="_blank">企业网站设计 </a><a href="http://m.cdcxhl.cn/mobile/" target="_blank">手机网站设计 </a><a href="http://www.cqcxhl.com/" target="_blank">重庆网站建设 </a><a href="http://chengdu.cdcxhl.cn/H5/" target="_blank">响应式网站设计 </a><a href="http://www.cxjianzhan.com/baojia/" target="_blank">网站建设费用 </a><a href="https://www.cdcxhl.com/h5.html" target="_blank">成都h5网站建设 </a><a href="http://www.scgulin.cn/" target="_blank">古蔺网站建设 </a><a href="http://www.dzwzjz.com/" target="_blank">达州网站设计 </a><a href="http://www.abwzjs.com/" target="_blank">阿坝网站设计 </a><a href="https://www.cdcxhl.com/" target="_blank">网站建设公司 </a><a href="http://m.cdcxhl.com/" target="_blank">成都网站制作 </a><a href="http://www.kswcd.com/service/" target="_blank">上市集团网站建设 </a><a href="http://chengdu.kswjz.com/" target="_blank">成都网站设计 </a><a href="http://seo.cdkjz.cn/mobile/" target="_blank">自适应网站设计 </a><a href="http://m.cdxwcx.com/" target="_blank">成都网站建设公司 </a><a href="http://chengdu.cdcxhl.cn/jianshe/" target="_blank">成都网站建设 </a><a href="http://www.cxhlcq.com/mobile/" target="_blank">重庆手机网站建设 </a><a href="https://www.cdxwcx.com/" target="_blank">成都网站建设公司 </a></div> </body> </html> <script src="/Public/Home/js/wow.min.js"></script> <script> if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) { new WOW().init(); }; </script> <div class="sidebar"> <ul> <li><a href="http://wpa.qq.com/msgrd?v=3&uin=244261566&site=www.bzwzjz.com&menu=yes" target="_blank"><img src="/Public/Home/images/right_qq.png" /></a></li> <li><a href="http://wpa.qq.com/msgrd?v=3&uin=1683211881&site=www.bzwzjz.com&menu=yes" target="_blank"><img src="/Public/Home/images/qq.png" /></a></li> <li class="tel"><a href="tel:028-86922220"><img src="/Public/Home/images/right_tel.png" /></a></li> <div class="wx"> <span class="weixin"><img src="/Public/Home/images/weixin.jpg"><br> 微信扫一扫在线咨询</span> </div> <li><a class="fx" href="#hero"><img src="/Public/Home/images/right_up.png" /></a></li> </ul> </div> <script type="text/javascript"> $(function () { $('.sidebar .fx').click(function () { $('html,body').animate({ scrollTop: '0px' }, 800); }); }); </script> <script type="text/javascript"> $(document).ready(function () { $("#fancybox-manual-b").click(function () { $.fancybox.open({ href: 'map.html', type: 'iframe', padding: 5 }); }) }); </script> <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>