我们专注孝感网站设计 孝感网站制作 孝感网站建设
成都网站建设公司服务热线:18982081108

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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://www.ytofo.com/article/gccdic.html">http://www.ytofo.com/article/gccdic.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/ippcoh.html">AndroidStudio如何修改字体的大小</a> </li><li> <a href="/article/ippcds.html">Python常用的数据类型有哪些</a> </li><li> <a href="/article/ippcij.html">如何在idea中使用tomcat远程debug</a> </li><li> <a href="/article/ippcis.html">C++在什么时候指定枚举值</a> </li><li> <a href="/article/ippcec.html">云主机的优缺点是什么呢</a> </li> </ul> </div> </div> <footer> <div class="message"> <div class="mess container"> <p>免费获取网站设计制作与品牌网站建设策划方案报价</p> <span>网站设计 + 品牌建站,策划方案 + 精准报价,现在免费领!品牌要升级,官网先发力!免费领取网站设计制作方案 + 精准报价,专业团队帮你落地</span> <form action=""> <input type="text" class="ipt1" placeholder="联系人"> <input type="text" class="ipt2" placeholder="联系电话"> <textarea name="" id="" placeholder="内容描述:描述您的需求,如网站、微信、电商、APP等。"></textarea> <a href="">提交需求</a> </form> </div> </div> <div class="footA"> <div class="footAs container"> <ul> <h3>联系我们</h3> <b>18980820575</b> <li>手机:13518219792</li> <li>地址:湖北孝感市大悟城关镇鄂北物流城13栋125号</li> <li class="hr1"></li> <li>24小时服务热线:18982081108</li> </ul> <ul> <h3>网站建设服务</h3> <li>网页设计</li> <li>网站制作</li> <li>网站开发</li> </ul> <ul> <h3>网站推广服务</h3> <li>营销网站建设</li> <li>百度快速排名</li> <li>整站网站推广</li> </ul> <ul> <h3>网站运维服务</h3> <li>基础维护</li> <li>网站改版</li> <li>网站维护</li> </ul> <ul> <h3>FOLLOW US</h3> <li class="hr2"></li> <li> <dd class="fl"><img src="/Public/Home/img/ewm.png" alt=""><p>微信二维码</p></dd> <dd class="fr"><img src="/Public/Home/img/ewm.png" alt=""><p>微信二维码</p></dd> </li> </ul> </div> <div class="link container"> 友情链接: <a href="http://www.cdkjz.cn/" title="成都网站制作" target="_blank">成都网站制作</a>   <a href="http://www.schzyjs.com/" title="成都喷绘" target="_blank">成都喷绘</a>   <a href="http://www.hmvxp.com/" title="成都公司注销代办公司" target="_blank">成都公司注销代办公司</a>   <a href="http://www.teliergzn.com/" title="特丽尔硅藻泥" target="_blank">特丽尔硅藻泥</a>   <a href="http://www.sxncvku.com/" title="成都柴油发电机租赁" target="_blank">成都柴油发电机租赁</a>   <a href="http://www.njanhua.com/" title="平面广告设计" target="_blank">平面广告设计</a>   <a href="http://www.hyjierui.cn/" title="hyjierui.cn" target="_blank">hyjierui.cn</a>   <a href="http://www.cdxwcx.cn/tuoguan/neijiang.html" title="四川内江电信机房" target="_blank">四川内江电信机房</a>   <a href="http://chengdu.cdweb.net/weixinkaifa/fuwuhao.html" title="微信服务号订阅号开发" target="_blank">微信服务号订阅号开发</a>   <a href="http://www.tpyxedu.com/" title="公司形象墙" target="_blank">公司形象墙</a>    </div> </div> <div class="footB"> <div class="container"> <div class="fl"> Copyright © 2025 湖北孝感网站建设公司 湖北孝感网站建设公司-选我们!湖北专业的孝感网站制作公司! </div> <div class="fr"> All Rights Reserved 版权所有 <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">鄂ICP备2025125038号-8</a> </div> </div> </div> </footer> </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>