溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

JSP如何實現(xiàn)頁面?zhèn)髦?/h1>
發(fā)布時間:2021-11-22 10:52:42 來源:億速云 閱讀:148 作者:小新 欄目:編程語言

這篇文章將為大家詳細講解有關JSP如何實現(xiàn)頁面?zhèn)髦?,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

這周在調(diào)支付寶的接口。期間需要把我方程序處理后的參數(shù)(交易金額)按照規(guī)定的格式傳遞給支付寶的接口。因為中途要設計到我方程序?qū)σ恍?shù)據(jù)的處理,所以并不方便直接傳值過去。思來想去,決定先把我方的數(shù)據(jù)提交給webwork的Action進行處理,也就是對數(shù)據(jù)庫進行操作;然后把交易金額以及支付寶接口需要的其他參數(shù)一并傳遞給一個JSP頁面,并讓這個JSP頁面在把action直接指向支付寶的網(wǎng)關接口,注意:中間過程中這個JSP頁面時不顯示出來的。為此,做了如下測試:建立兩個JSP頁面?zhèn)髦?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. <html> 

  8. <head> 

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

  10.  

  11. <title>MyJSP'test1.jsp'startingpagetitle> 

  12. <metahttp-equivmetahttp-equiv="pragma"content="no-cache"> 

  13. <metahttp-equivmetahttp-equiv="cache-control"content="no-cache"> 

  14. <metahttp-equivmetahttp-equiv="expires"content="0"> 

  15. <metahttp-equivmetahttp-equiv="keywords"content="keyword1,keyword2,keyword3"> 

  16. <metahttp-equivmetahttp-equiv="description"content="Thisismypage"> 

  17. <metahttp_equivmetahttp_equiv="refresh"content="5"> 

  18.  

  19. <scriptlanguagescriptlanguage="javascript"type="text/javascript"> 

  20. functionexecute(){  

  21. varobj=document.getElementById("name");  

  22. document.form1.action="alipay/test2.jsp?param="+obj.value;  

  23. document.form1.submit();  

  24. }  

  25. script> 

  26. head> 

  27. <bodyonloadbodyonload="execute();"> 

  28. <formnameformname="form1"method="post"> 

  29. <table> 

  30. <tr> 

  31. <td> 

  32. 測試JSP頁面?zhèn)髦?span id="eiljylq" class="tag"><inputtypeinputtype="text"id="username"value="luodada"> 

  33. td> 

  34. tr> 

  35. table> 

  36. form> 

  37. body> 

  38. html> 

tset2.jsp的代碼如下:

<%@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>

具體思路如下:

在JSP頁面?zhèn)髦祎est1.jsp中,通過JavaScript把文本框中的值獲取出來,,使test1.jsp在加載進來的時候馬上執(zhí)行頁面跳轉;

在JSP頁面?zhèn)髦祎est2.jsp中通過request.getParameter("參數(shù)名稱");來獲取test1.jsp傳遞過來的值即可。

關于“JSP如何實現(xiàn)頁面?zhèn)髦怠边@篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)
AI