Request的重定向方法以及中文显示问题

前几天老师给我们的作业当中我发现因为我们用的浏览器的种类不一样。所以大家都出现了中文变成乱码的问题。
在LoginServlet这个Servlet这个类当中,通过使用Request的sendRedirect方法重定向一张网页
我在firefox 浏览器中用输入内容,最后出现了乱码,然后 又在TT和IE当中试了试,没有发现这样的问题。说明firefox对中文支持的不是很好,因此在WEB编程中,希望能加上<meta http-equiv="content-type" content="text/html; charset=gb2312">这一句。这样用什么浏览器都会是中文的了!


login.html

<html>
    <head>
        <title>登录页面</title>
    </head>
    <body>
        <form action="login" method="post">
            <table>
                <tr>
                    <td>请输用户名:</td>
                    <td><input type="text" name="user"></td>
                </tr>
                <tr>
                    <td>请输入密码:</td>
                    <td><input type="text" name="password"></td>
                </tr>
                <tr>
                    <td><input type="submit" value="登陆"></td>
                    <td><input type="reset" value="重填"></td>
                </tr>
            </table>
        </form>
    </body>
</html>

LoginServlet .java

package com.wizard.chenxi.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 LoginServlet extends HttpServlet{
    public void doGet(HttpServletRequest req,HttpServletResponse resp)
                    throws ServletException,IOException{
        resp.setContentType("text/html;charset=gb=2312");
        
        String name = req.getParameter("user");
        String pwd = req.getParameter("password");
        
        if(name!=null && pwd!=null && name.equals("Chenxi") && pwd.equals("1234")){
            resp.sendRedirect("success.html");
            
        }else{
            resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,"服务器忙");
        }
    }// end for doGet
    public void doPost(HttpServletRequest req,HttpServletResponse resp)
                    throws ServletException,IOException{
        doGet(req,resp);
    }
}// end for class

success.html

<html>
    <head>
        <title>登录成功</title>
    </head>
    <body>
        登录成功,欢迎!
    </body>
</html>

web.xml
。。。。。
。。
   <servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>com.wizard.chenxi.servlet.LoginServlet</servlet-class>
  </servlet>
    <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/login</url-pattern>
  </servlet-mapping>

。。。。。



 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值