Topic: [求助]Servlet奇怪问题

  Print this page

1.[求助]Servlet奇怪问题 Copy to clipboard
Posted by: robinlet
Posted on: 2005-04-23 20:40

写了一个简单的Servlet

package edu.hit.ims.study.servlet;

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

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class MyServlet
extends HttpServlet {

public void init(ServletConfig config) throws ServletException {
super.init(config);
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType("test/html;charset=GB2312");

PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>Hello Servlet!</head>");
out.println("<body>");
out.println("Hello World!");
out.println("大家好!");
out.println("</body>");
out.println("</html>");
out.close();
}

public String getServletInfo() {
return "edu.hit.ims.study.servlet.MyServlet Information!";
}

public void destroy() {

}

}

一个HelloJsp.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
hellojsp
</title>
</head>
<body bgcolor="#ffffff">
<h1>
Hello!jsp
</h1>
<form method="post">
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>

web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>edu.hit.ims.study.servlet.MyServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>debugjsp</servlet-name>
<description>Added to compile JSPs with debug info</description>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>classdebuginfo</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>HelloJsp.jsp</welcome-file>
</welcome-file-list>
</web-app>

使用 jb9, ie6

在浏览器中输入
http://localhost:8083/webapp/MyServlet
提示让我选择保存/打开MyServlet 文件。
输入 http://localhost:8083/webapp/HelloJsp.jsp
http://localhost:8083/webapp/
提示让我选择保存/打开 HelloJsp.jsp文件。

但是我选择用IE打开的时候又能正常显示。
这是怎么回事?????很奇怪。

2.Re:[求助]Servlet奇怪问题 [Re: robinlet] Copy to clipboard
Posted by: bluepure
Posted on: 2005-04-23 21:37

servlet的
response.setContentType("test/html;charset=GB2312");

--〉

response.setContentType("text/html;charset=GB2312");

不过jsp的就不知道为什么了:(

3.Re:[求助]Servlet奇怪问题 [Re: robinlet] Copy to clipboard
Posted by: robinlet
Posted on: 2005-04-23 21:47

已经解决了,jsp也没问题了。原来是粗心笔误造成的。
一开始还以为是MIME类型不支持,想设置mime-mapping来着。呵呵


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923