我在写servlet小程序的时候,遇到一个问题。比方说importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServl...
我在写servlet小程序的时候,遇到一个问题。比方说
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 6189969869246489166L;
public void doPost(HttpServletRequest aHSRequest, HttpServletResponse aHSResponse)
throws ServletException, IOException {
aHSResponse.setContentType("text/html;charset=utf-8");
PrintWriter pW = aHSResponse.getWriter();
pW
.println(""-//W3C//DTD HTML 4.01 Transitional//EN\">");
pW.println("");
pW.println("
A Servlet");pW.println("
");aHSRequest.setCharacterEncoding("utf-8");
pW.print("
注册成功
");pW.println("
");
pW.print("您的用户名为:" + aHSRequest.getParameter("UserName")+"
");
pW.print("您的密码为:" + aHSRequest.getParameter("Password"));
pW.println(" ");
pW.println("");
pW.flush();
pW.close();
}
}
结果还是出现了乱码。但是把utf-8改成gbk就好了。哪位仁兄来解释下。
我用的是myeclipse。web.xml如下
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
This is the description of my J2EE component
This is the display name of my J2EE component
LoginServlet
LoginServlet
LoginServlet
/servlet/LoginServlet
index.jsp
展开