servlet解决中文乱编的问题(6)
来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:48 点击:次
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 check extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
String newname = new String(request.getParameter("username").getBytes(
"ISO-8859-1"), "GBK");
PrintWriter out = response.getWriter();
out.print("<html><head></head><body>GET方式提交<br/><h2>" + newname);
out.print("</h2></body></html>");
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
//request.setCharacterEncoding("GBK");
System.out.println("调用doPost");
String newname = request.getParameter("username");
PrintWriter out = response.getWriter();
out.print("<html><head></head><body>POST方式提交<br/><h2>" + newname);
out.print("</h2></body></html>");
out.close();
}
}
package com.mars;
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 check extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
相关新闻>>
- 发表评论
-
- 最新评论 更多>>