本文详细介绍JSP页面传值,以及建立两个JSP页面,tes1.jsp和test2.jsp,包括其JSP页面代码。

这周在调支付宝的接口。期间需求把我方程序处理后的参数(买卖金额)依照规则的格局传递给支付宝的接口。由于半途要规划到我方程序对一些数据的处理,所以并不便利直接传值曩昔。思来想去,决议先把我方的数据提交给webwork的Action进行处理,也便是对数据库进行操作;然后把买卖金额以及支付宝接口需求的其他参数同时传递给一个JSP页面,并让这个JSP页面在把action直接指向支付宝的网关接口,留意:中心过程中这个JSP页面时不显现出来的。为此,做了如下测验:树立两个JSP页面传值,tes1.jsp和test2.jsp。代码如下:

详解JSP页面传值(jsp页面传值的方法)  JSP页面传值 第1张

  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. <html>
  8. <head>
  9. <basehrefbasehref="">
  10. <title>MyJSP'test1.jsp'startingpagetitle>
  11. <metahttp-equivmetahttp-equiv="pragma"content="no-cache">
  12. <metahttp-equivmetahttp-equiv="cache-control"content="no-cache">
  13. <metahttp-equivmetahttp-equiv="expires"content="0">
  14. <metahttp-equivmetahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
  15. <metahttp-equivmetahttp-equiv="description"content="Thisismypage">
  16. <metahttp_equivmetahttp_equiv="refresh"content="5">
  17. <scriptlanguagescriptlanguage="javascript"type="text/javascript">
  18. functionexecute(){
  19. varobj=document.getElementById("name");
  20. document.form1.action="alipay/test2.jsp?param="+obj.value;
  21. document.form1.submit();
  22. }
  23. script>
  24. head>
  25. <bodyonloadbodyonload="execute();">
  26. <formnameformname="form1"method="post">
  27. <table>
  28. <tr>
  29. <td>
  30. 测验JSP页面传值<inputtypeinputtype="text"id="username"value="luodada">
  31. td>
  32. tr>
  33. table>
  34. form>
  35. body>
  36. html>

tset2.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. <html>
  8. <head>
  9. <basehrefbasehref="">
  10. <title>MyJSP'test2.jsp'startingpagetitle>
  11. <metahttp-equivmetahttp-equiv="pragma"content="no-cache">
  12. <metahttp-equivmetahttp-equiv="cache-control"content="no-cache">
  13. <metahttp-equivmetahttp-equiv="expires"content="0">
  14. <metahttp-equivmetahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
  15. <metahttp-equivmetahttp-equiv="description"content="Thisismypage">
  16. head>
  17. <body>
  18. <%
  19. Stringvalue=request.getParameter("param");
  20. out.print("从test1.jsp传递过来的值是"+value);
  21. %>
  22. body>
  23. html>

详细思路如下:

在JSP页面传值test1.jsp中,经过JavaScript把文本框中的值获取出来,,使test1.jsp在加载进来的时分立刻履行页面跳转;

在JSP页面传值test2.jsp中经过request.getParameter("参数称号");来获取test1.jsp传递过来的值即可。

【修改引荐】

  1. 详解JSP中调用JavaBean
  2. JSP开发环境的建立
  3. 处理JSP开发Web程序中文显现三种办法
  4. 开发JSP HTTP服务器
  5. JSP、ASP和PHP安全编程
转载请说明出处
知优网 » 详解JSP页面传值(jsp页面传值的方法)

发表评论

您需要后才能发表评论