我所了解的servlet传值的方式

1. 定向传值

 

request.setAttribute("key", value);
request.getRequestDispatcher("index.jsp").forward(request, response);

2. ajax+servlet


//生成JSON数据

JSONArray arr = new JSONArray(valueList);
String arrString = arr.toString();
		
//响应到客户端		
request.setCharacterEncoding("utf-8");
response.setContentType("text/plain;charset=utf-8");
response.getWriter().print(arrString);			

3. 页面响应传值

if(null != ui){
	request.getSession().setAttribute("key", value);
	response.sendRedirect("index.jsp");
}else {
	request.setCharacterEncoding("utf-8");
	response.setContentType("text/html;charset=utf-8");
			
	PrintWriter pw = response.getWriter();
	StringBuffer sb = new StringBuffer();
	sb.append("");
	pw.write(sb.toString());
}


你可能感兴趣的:(Ajax,;,servlet)