servlet里面的中文怎么显示?(50分)

  • 主题发起人 主题发起人 D影子D
  • 开始时间 开始时间
D

D影子D

Unregistered / Unconfirmed
GUEST, unregistred user!
如下所示:
漱壕.% ()VCodeLineNumberTabledoGetR(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V Exceptions SourceFile Test.java A
This is a servlet test.濂界殑!
! "# $ Test/Testjavax/servlet/http/HttpServletjavax/servlet/ServletExceptionjava/io/IOException&javax/servlet/http/HttpServletResponse getWriter()Ljava/io/PrintWriter;java/io/PrintWriterprintln(Ljava/lang/String;)Vflush! * 6,N--
都是什么?怎么显示?我只显示 This is a servlet test.濂界殑!
这句话而已阿。怎么多出这么多呢?
 
有人用过servlet吗?帮帮我
 
你加上了
<%@ page contentType="text/html;charset=gb2312" %>
了吗?
 
request.setCharacterEncoding("GB2312");
 
to Inboy 我刚学,我在浏览器输入
http://202.205.177.236:8080/Test.class
可是弹出对话框要我下载或运行,为什么?怎么执行这个servlet
 
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class DzLogin extends HttpServlet{
static final private String CONTENT_TYPE= "text/html;
charset=GBK";
//声明中文字符集
public voiddo
Post(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
//设置显示中文字符
PrintWriter out= response.getWriter();

out.print("对不起哈哈哈哈哈哈哈哈 !");

String s1= request.getParameter("s1").trim();
s1=new String(s1.getBytes("iso-8859-1"),"GBK");
//把经过编码数据查入数据库就不会乱码了
}

}

需要配置web.xml文件
<servlet>
<servlet-name>UpLogin</servlet-name>
<servlet-class>PuDong.Huabo.Web.DataDispense.UpLogin</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>UpLogin</servlet-name>
<url-pattern>/UpLogin</url-pattern>
</servlet-mapping>
 
多人接受答案了。
 
后退
顶部