response.setContentType("text/html");
response.setCharacterEncoding("utf-8"); 把这句加上,且重启Tomcat即可,页面刷新即可。要重启Tomcat才行。
网址: http://localhost:8080/HelloForm?first_name=ffffff&last_name=ddd即看到修改后的效果
</pre><pre name="code" class="java">// 导入必需的 java 库
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// 扩展 HttpServlet 类
public class HelloForm extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
// 设置响应内容类型
response.setContentType("text/html");
response.setCharacterEncoding("utf-8"); 把这句加上,且重启Tomcat即可,页面刷新即可。要重启Tomcat才行。
PrintWriter out = response.getWriter