您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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。代碼如下:
<%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"://"+request.getServerName()
+":"+request.getServerPort()+path+"/";%>
>
<html>
<head>
<basehrefbasehref="<%=basepath%>">
<title>MyJSP'test1.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">
<metahttp_equivmetahttp_equiv="refresh"content="5">
<scriptlanguagescriptlanguage="javascript"type="text/javascript">
functionexecute(){
varobj=document.getElementById("name");
document.form1.action="alipay/test2.jsp?param="+obj.value;
document.form1.submit();
}
script>
head>
<bodyonloadbodyonload="execute();">
<formnameformname="form1"method="post">
<table>
<tr>
<td>
測試JSP頁面?zhèn)髦?span id="eiljylq" class="tag"><inputtypeinputtype="text"id="username"value="luodada">
td>
tr>
table>
form>
body>
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)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。