想請教各位大大,如果javascript的參數想要輸出之後,傳給JSP請問有辦法做嗎?,
先取得按鈕數字i的值,然後傳進參數Tbpage,然後我想把Tbpage的I值取出來,給PageA做運算,想請問有辦法做嗎?謝謝~
看你的問題應該是要依照按鈕按壓次數跳到對應的頁面,是嗎 ???
貼個 submit 的方試給你參考(不過是用jQuery):ItAns0516.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Darwin's Lab</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
var txtId = 1;
$(function() {
$("#countBtn").click(function() {
txtId++;
$("#countBtn").val(txtId);
$("#countId").val(txtId);
});
})
</script>
</head>
<body>
<form id="form1" action="post.jsp" name="form1" method="post">
<center>
<input type="button" name="countBtn" value="1" id="countBtn">
<input type="submit" value="submit">
<!-- 把計數的資訊丟給hidden欄位儲存再Submit -->
<input type="hidden" name="countId" value="1" id="countId">
</center>
</form>
</body>
</html>
提交後的處理頁面post.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Darwin's Lab</title>
</head>
<body>
Count:<%=request.getParameter("countId")%>
</body>
</html>
post.jsp可依你的需求用 switch 或 if-else 判斷後,再用
<jsp:forward page="前往頁面"/>
W3School jQuery Tutorial
最後,學一下jQuery吧,程式碼會乾淨許多!