日期:2014-05-17  浏览次数:20738 次

为什么我一请求servlet就弹出下载页面
最近在学servlet,按书本上的demo写,出现请求servlet网页就出现下载框的问题,求解
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ch5_example</display-name>

  <servlet>
    <servlet-name>ListenerTester</servlet-name>
    <servlet-class>com.example.web.ListenerTester</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ListenerTester</servlet-name>
    <url-pattern>/ListenTest.do</url-pattern>
  </servlet-mapping>
  <listener>
    <listener-class>com.example.web.MyServletContextListener</listener-class>
  </listener>
  
  <context-param>
    <param-name>breed</param-name>
    <param-value>Great Dane</param-value>
  </context-param>
</web-app>

Dog类:
public class Dog {

private String breed;

public Dog(String breed) {
super();
this.breed = breed;
}

public String getBreed() {
return breed;
}

public void setBreed(String breed) {
this.breed = breed;
}

}

ListenerTester:
public class ListenerTester extends HttpServlet {
private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListenerTester() {
        super();
        // TODO Auto-generated constructor stub
    }

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExceptionIOException {
// TODO Auto-generated method stub
response.setContentType("test/html");