GreetingServlet.java:
package servlets;

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class GreetingServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setBufferSize(8192);
request.setCharacterEncoding("GB2312");
response.setContentType("text/html;charset=GB2312");
PrintWriter out = response.getWriter();

// then write the data of the response
out.println("<html>" + "<head><title>Hello</title></head>");

// then write the data of the response
out.println("<body bgcolor=\"#ffffff\">" +
"<h2>Hello, my name is Duke. What is yours?</h2>" +
"<form method=\"get\">" +
"<input type=\"text\" name=\"username\" size=\"25\">" + "<p></p>" +
"<input type=\"submit\" value=\"Submit\">" +
"<input type=\"reset\" value=\"Reset\">" + "</form>");
String username = request.getParameter("username");

if ((username != null) && (username.length() > 0)) {
RequestDispatcher dispatcher =
getServletContext()
.getRequestDispatcher("/response");

if (dispatcher != null) {
dispatcher.include(request, response);
}
}

out.println("</body></html>");
out.close();
}

public String getServletInfo() {
return "The Hello servlet says hello.";
}
}

ResponseServlet.java:

package servlets;

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ResponseServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GB2312");
PrintWriter out = response.getWriter();
// then write the data of the response
//String username = request.getParameter("username");
String username=new String(request.getParameter("username").getBytes(" ISO-8859-1"),"GB2312");
if ((username != null) && (username.length() > 0)) {
// String s=request.getParameter("username");
// byte a[]=s.getBytes("ISO-8859-1");
// username=new String(a);
out.println("<h2>Hello, " + username + "!</h2>");
}
}

public String getServletInfo() {
return "The Response servlet says hello.";
}
}

SetCharacterEncodingFilter.java:
package filters;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.*;

public class SetCharacterEncodingFilter implements Filter {

protected String encoding = null;

protected FilterConfig filterConfig = null;

protected boolean ignore = true;

public void destroy() {

this.encoding = null;
this.filterConfig = null;

}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {

// Conditionally select and set the character encoding to be used
if (request.getCharacterEncoding() == null) {
if (this.encoding != null){
request.setCharacterEncoding(encoding);
((HttpServletResponse) response).setContentType("text/html; charset=" + encoding);
}
}


// Pass control on to the next filter
chain.doFilter(request, response);

}
public void init(FilterConfig filterConfig) throws ServletException {

this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;

}

protected String selectEncoding(ServletRequest request) {

return (this.encoding);

}


}

web.xml:
<display-name>hello2</display-name>
<filter>
<filter-name>SetCharacterEncodingFilter</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<servlet>
<display-name>GreetingServlet</display-name>
<servlet-name>GreetingServlet</servlet-name>
<servlet-class>servlets.GreetingServlet</servlet-class>
</servlet>
<servlet>
<display-name>ResponseServlet</display-name>
<servlet-name>ResponseServlet</servlet-name>
<servlet-class>servlets.ResponseServlet</servlet-class>
</servlet>
<filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet-mapping>
<servlet-name>GreetingServlet</servlet-name>
<url-pattern>/greeting</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ResponseServlet</servlet-name>
<url-pattern>/response</url-pattern>
</servlet-mapping>

I don't write the first part of the web.xml.When I submit the chinese,it shows ???.Can you help me? Thank you very much.