*
忽视它
*
我更熟悉JSP和java领域。我遇到了问题。我在下面提到了我的代码。
我的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>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#save").click( function ()
{
var arrayxx= new Array(5);
arrayxx[0]=0;
arrayxx[1]=3;
arrayxx[2]=4;
arrayxx[3]=9;
$.get('Save1',{arrayX:arrayxx},function(responseJson)
{
} );
});
});
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<input type="button" id="save" value="save" ></input>
</body>
</html>
我的servlet:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Save1 extends HttpServlet {
private static final long serialVersionUID = 1L;
public Save1() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("INSIDE SERVLET");
String [] yourList = request.getParameterValues("arrayX");
System.out.println(request.toString());
System.out.println(yourList[0]);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
我无法将数组从JSP传递给servlrt。 请帮我解决一下这个。当我收到数组时,我发现该数组不包含任何元素。
提前致谢
答案 0 :(得分:0)
根据您的要求,我建议您像这样使用ajax
$.ajax(
{
type: "POST",
url: "servlet", //Your full URL goes here
data: { parametername: parametervalue},
success: function(data, textStatus, jqXHR){
//alert(data);
}