我建了一个servlet
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 pp extends HttpServlet { /**
 * Constructor of the object.
 */
public pp() {
super();
} /**
 * Destruction of the servlet. <br>
 */
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
 * The doGet method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to get.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println("  <BODY>");
out.print("    This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println("  </BODY>");
out.println("</HTML>");
out.flush();
out.close();
} /**
 * The doPost method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println("  <BODY>");
out.print("    This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println("  </BODY>");
out.println("</HTML>");
out.flush();
out.close();
} /**
 * Initialization of the servlet. <br>
 *
 * @throws ServletException if an error occure
 */
public void init() throws ServletException {
// Put your code here
}}
web.xml如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>pp</servlet-name>
    <servlet-class>pp</servlet-class>
  </servlet>  <servlet-mapping>
    <servlet-name>pp</servlet-name>
    <url-pattern>/servlet/pp.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
为什么我地址栏里(http://192.168.0.199%20:8080/tt/servlet/pp.do)打不开呢 
不知道什么原因 
小弟刚学java 问题比较若 别鄙视哈

解决方案 »

  1.   

    提示这个description The requested resource (/servlet/pp.do) is not available.
      

  2.   

    你的代码经测试没有问题 输出结果This is class pp, using the GET method 看你输入的地址http://192.168.0.199%20:8080/tt/servlet/pp.do怎么会多一个%20,也就是中文状态的空格
      

  3.   

    改正了上面说的错误后 down掉服务 重新部署 start服务 再看看还报什么错
      

  4.   

    <servlet-class>pp</servlet-class>
    不知道你的有没有包啊
    http://192.168.0.199%20:8080/tt/servlet/pp.do
    改成http://127.0.0.1:8080/tt/servlet/pp.do试试
      

  5.   

    解决了 tomcat/web-inf里面要配置一下