2008年11月23日星期日

写了段垃圾代码,发现IE和FireFox的展现是不一样的

代码在下边
[code]
package cn.siox.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class TestApp
*/
public class TestApp extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public TestApp() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
request.getSession(true);
PrintWriter out=response.getWriter();
out.println("你好,我的朋友");
out.println("path="+request.getServletPath());
out.println("The session ID="+request.getSession().getId());
out.println("session ID is New?---->"+request.getSession().isNew());
out.println("The Cookies="+request.getCookies());
out.flush();
out.close();
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}

}
[/code]

[web.xml]




test
cn.siox.web.servlet.TestApp


test
/test



[/web.xml]

起初,firefox正确解析,IE解析乱码,在浏览器端把码格式调一下OK
在发现就是IE不符合标准,firefox能正确换行IE不行
调成gbk,发现firefox又是乱码,好吧,好在firefox有自动检测功能,不像IE就是一傻子

结果:

firefox:

你好,我的朋友
path=/test
The session ID=4FA4523A641DFD9776A95ECAA46AFE58
session ID is New?---->false

IE:

你好,我的朋友 path=/test The session ID=E4FFA8C9C59A30FB2D54EE750433F589 session ID is


New?---->false The Cookies=[Ljavax.servlet.http.Cookie;@13c0b53
The Cookies=[Ljavax.servlet.http.Cookie;@e49dcd

没有评论: