나는 요구 사항이 있습니다. 즉, 서블릿에 자바 스크립트 배열을 전달해야합니다. 저를 안내 해주세요 감사합니다
qwe.js
<script type="text/javascript">
var array2 = [];
function getTotalTests() {
console.log("called");
console.log("called"+array1.length);
for (i=0; i < array1.length; i++) {
array2[i] = array1[i];
console.log(array2[i]);
}
};
</script>
서블릿에 array2를 전달해야합니다.
JSP 페이지
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
function func()
{
var arr=[2,3,3];
var form = $('<form action="Test" method="get">' +
'<input type="hidden" name="id" value="'+arr+'">' +
'</form>');
alert( $(form));
$(form).submit();
}
</script>
<body>
<button onclick="func()">Deepak</button>
</body>
</html>
서블릿
package test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Test
*/
@WebServlet("/Test")
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public Test() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println(request.getParameter("id"));
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다