日期:2014-05-18  浏览次数:20737 次

servlet入门的问题,HelloWorld
第1次用servlet,就有问题
一个HelloWorldServlet
import   java.io.*;
import   javax.servlet.*;
import   javax.servlet.http.*;

public   class   HelloWorldServlet   extends   HttpServlet  
{
public   void   doGet(HttpServletRequest   request,HttpServeltResponse   response)   throws   IOException,ServletException
{
response.setContentType( "text/heml;charset=gb2312 ");
PrintWriter   out=response.getWriter();

out.println( " <html> ");
out.println( " <head> ");
out.println( " <title> HelloWorld </title> ");
out.println( " </head> ");
out.println( " <body   bgcolor=\ "white\ "> ");
out.println( " <hr> ");
out.println( "HelloWorld ");
out.println( "你好世界 ");
out.println( " </body> </html> ");
}
public   void   doPost(HttpServletRequest   request,HttpServletResponse   response)   throws   IOException,ServletException
{
doGet(request,response);
}
}
一个web.xml
<?xml   version= "1.0 "   encoding= "ISO-8859-1 "?>

<web-app   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   web-app_2_4.xsd "
        version= "2.4 ">

    <display-name> Welcome   to   Tomcat </display-name>
    <description>
        JSP应用开发详解
    </description>
        <servlet>
                <servlet-name> HelloWorldServlet </servlet-name>
                <servlet-class> jsp.HelloWorldServlet </servlet-class>
        </servlet>
        <servlet-mapping>
                <servlet-name> HelloWorldServlet </servlet-name>
                <url-pattern> /hello </url-pattern>
        </servlet-mapping>
</web-app>
===============================
两个文件用笔记本编辑好后,放在Tomcat5.5\webapps\jsp文件夹下
然后在浏览器中:http://127.0.0.1:8080/jsp/hello
显示HTTP   Status   404   -   /jsp/hello

type   Status   report

message   /jsp/hello

description   The   requested   resource   (/jsp/hello)   is   not   available

在之前编译HelloWorldServlet时,也出错,说找不到javax.servlet,javax.servlet.http,HttpServletResponse,HttpServletRequest不存在或找不到之类的提示,郁闷~

请高手指点,小弟先谢了


------解决方案--------------------
又看了次没看出来
我就把你的文件部署了下...
才发现
public void doGet(HttpServletRequest request,HttpServeltResponse response) throws IOException,ServletException
这行的HttpServeltResponse应该写成HttpServletResponse
笔误了
再出错误的话
贴出错误来吧