一、jsp之间传值时乱码问题解决

request.setCharacterEncoding("GBK");//解决中文乱码
String postData = (String)request.getParameter("hideCoords"); //获取上个页面传入的值

二、如果传过来的值是用的checkbox则用数组接收参数

request.setCharacterEncoding("GBK");//解决中文乱码
String showInfo[] = request.getParameterValues("insert");//insert为checkbox的name

三、response对象用来返回信息对客户端

response.setHeader("refresh","3");//每隔三秒刷新一次页面
response.setHeader("refresh","3;URL=show.jsp");//三秒后跳转到show页面

由于跳转时地址栏发生了改变,所以这种改变地址栏的跳转称为客户端跳转。

除了用setHeader进行跳转,还可以用下面的进行页面跳转(客户端跳转)

response.sendRedirect("show.jsp");

服务器跳转

<jsp:forward page="show.jsp"/>//服务器跳转,地址栏的地址不改变

 服务器跳转会马上执行跳转,而客户端跳转则是执行完本页面后再执行跳转。例如:

<%
   System.out.println("###跳转之前");
   response.sendRedirect("show.jsp");
   System.out.println("###跳转之前");
%>
tomcat输出
###跳转之前
###跳转之前

<%
   System.out.println("###跳转之前");
   <jsp:forward page="show.jsp">
   System.out.println("###跳转之前");
%>
tomcat输出
###跳转之前

 

相关文章:

  • 2021-09-20
  • 2021-09-24
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2021-09-12
猜你喜欢
  • 2021-11-25
  • 2022-12-23
  • 2021-12-22
  • 2021-10-21
  • 2021-11-16
  • 2021-07-21
  • 2021-09-05
相关资源
相似解决方案