forward指令乱码问题

  1.    forward1.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<center>
<form action="forward2.jsp" method="get" >
      用户名:<input type="text" name="user" /><br>
       密码: <input type="text" name="password" /><br>
    <input type="submit" value="登陆"/>
    <input type="reset" value="取消"/>
   </form>
</center>
</html>

2. forward2.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
 <%
  String user=request.getParameter("user");
  String password=request.getParameter("password");
  if(user.equals("admin") && password.equals("admin")) { %>
     <jsp:forward page="success.jsp"/>
  <% }
  else
  { %>
    <jsp:forward page="fail.jsp"/>
  <% } %>

3.success.jsp

<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%  //request.setCharacterEncoding("utf-8"); %>  
<h3>登陆成功</h3>

4. fail.jsp

<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%//   request.setCharacterEncoding("utf-8"); %>  
<h3 align=center><font color=red>登录失败,请重新登录</font></h3>



注:之前 2,3,4开头加上这条语句"
<span style="font-size:14px;color:#ff0000;"><%@ page contentType="text/html; charset=utf-8" language="java"%></span>
 可解决页面跳转时的乱码

猜你喜欢

转载自blog.csdn.net/qq_18062811/article/details/51171308