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> 文章出自:<a href="http://hxwzsj.com/article/gccdic.html">http://hxwzsj.com/article/gccdic.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/doijisd.html">包含c语言中什么是系统函数的词条</a> </li><li> <a href="/article/doijisg.html">智能聊天海外 海外chr</a> </li><li> <a href="/article/doijidc.html">网站程序帝国CMS 帝国cms 小程序</a> </li><li> <a href="/article/doijeod.html">go语言查找函数手册 go语言查询数据库</a> </li><li> <a href="/article/doijeds.html">zblog显示运营天数 zblog负载怎么样</a> </li> </ul> </div> </div> <div class="footer2"> Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14 <br />友情链接: <a href="http://www.cqcxhl.com/" target="_blank">重庆企业网站建设 </a><a href="https://www.cdxwcx.com/wangzhan/pinpai.html" target="_blank">高端品牌网站建设 </a><a href="http://www.kswcd.com/mobile/" target="_blank">手机网站建设 </a><a href="http://www.cdxwcx.cn/" target="_blank">成都网站设计 </a><a href="http://www.cdweb.net/" target="_blank">成都网站建设 </a><a href="http://www.33260.cn/" target="_blank">成都定制网站建设 </a><a href="https://www.cdxwcx.com/wangzhan/mbqiye.html" target="_blank">成都企业网站制作 </a><a href="http://www.cdweb.net/" target="_blank">自适应网站建设 </a><a href="http://www.cqcxhl.com/service/foreigntrade.html" target="_blank">重庆外贸网站建设 </a><a href="http://www.cdxwcx.cn/" target="_blank">成都网站建设 </a><a href="http://chengdu.xwcx.net/mobile/" target="_blank">手机网站建设套餐 </a><a href="http://www.cxjianzhan.com/baojia/" target="_blank">网站建设费用 </a><a href="http://m.cdcxhl.cn/H5/" target="_blank">成都响应式网站建设 </a><a href="http://www.cqcxhl.com/" target="_blank">重庆网站制作 </a><a href="https://www.cdcxhl.com/yingxiao.html" target="_blank">成都营销网站建设 </a><a href="https://www.cdcxhl.com/sheji/chengdu.html" target="_blank">四川成都网站设计 </a><a href="http://chengdu.cdcxhl.cn/dingzhi/" target="_blank">定制网站设计 </a><a href="http://www.cdxtjz.com/" target="_blank">网站制作 </a><a href="http://www.cxhlcq.com/zhizuo/" target="_blank">重庆网站制作 </a><a href="http://www.dzwzjz.com/" target="_blank">达州网站设计 </a><a href="http://www.lzwzjz.cn/" target="_blank">泸州网站建设 </a><a href="http://m.cdcxhl.cn/mobile/" 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=hxwzsj.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=hxwzsj.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>