幾種JSP頁面傳值方式:
1. 隱藏欄位傳值:
<form method="post" action="client_crud.jsp" >
<input type="hidden" name="id" value="<%=id %>">
2. URL傳值:
用button
a.
<input name="btnModify" type="button" class="button1" onClick="self.location='client_modify.jsp?id=<%=id %>'"
value="修改分銷商" />
b.把input的onClick=”modifyRegion()”
function modifyRegion() {
window.self.location = client_node_modify.jsp?id=<%=id%>";
}
3. JS方式傳值
//取得form對象提交表單
with(document.getElementById("userForm")) {
method="post";
action="user_add.jsp?command=add";
submit();
}
function searchItem() {
with(document.forms[0]) {
action="servlet/basedata/SearchItemServlet";
method="post";
submit();
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
JSP的幾種參數傳值:
JSP的幾種參數傳值:
一、超連結
<a href="P.jsp?username=zhangshan&pwd=123456&age=25"> 連結</a>
二、forma表單
1.可顯示的控制項
<input type="text" name="username">
2.如果要傳遞的值,不需要顯示在頁面上
(1)<input type="hidden" name="pwd" value="<%=pwd%>">
(2)<form action="XXX.jsp" method="post"></form>
三、JSP的include和forward標籤
<jsp:include flush="true" page="T.jsp?username=zhangshan&pwd=123456678">
<jsp:param name="age" value="28"/>
</jsp:include>
四、javascript方式
script type="text/javascript">
function demo(){
var v = document.all('username').value;
location.replace("V.jsp?username="+v+"&age=25");
}
</script>
<input type="text" name="username"><br>
<input type="button" value="href點擊" onclick="location.href='V.jsp?pwd=123456'"><BR>
<input type="button" value="replace點擊"
onclick="location.replac('V.jsp?pwd=123456789')">
<br>
<input type="button" value="動態取值" onclick="demo()">