首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

为什么小弟我的配置都是对了,servlet在浏览器里还是显示不出来啊

2011-12-21 
为什么我的配置都是对了,servlet在浏览器里还是显示不出来啊?//这是我的servlet文件,有class文件在dopost\

为什么我的配置都是对了,servlet在浏览器里还是显示不出来啊?
//这是我的servlet文件,有class文件在dopost\WebRoot\WEB-INF\classes\post下生成
package   post;

import   java.io.IOException;
import   java.io.PrintWriter;
import   java.util.Enumeration;

import   javax.servlet.ServletException;
import   javax.servlet.http.HttpServlet;
import   javax.servlet.http.HttpServletRequest;
import   javax.servlet.http.HttpServletResponse;

public   class   SerPost   extends   HttpServlet
{
private   static   final   String   CONTENT_TYPE   =   "text/html;charset=GBK ";
public   void   init()   throws   ServletException{}
public   void   doPost(HttpServletRequest   request,   HttpServletResponse   response)
throws   ServletException,IOException
{
request.setCharacterEncoding(CONTENT_TYPE);
PrintWriter   out   =   response.getWriter();
out.println( " <html> ");
out.println( " <head> \n <title> \nSerPost\n </title> \n </head> ");
out.println( " <body> ");
out.println( " <p> The   Servlet   has   received   a   POST.This   is   the   reply. </p> ");
Enumeration   e   =   request.getParameterNames();
while   (e.hasMoreElements())
{
String   name   =   (String)e.nextElement();
String   value   =   request.getParameter(name);
out.println(name+ "=== "+value);
}
out.println( " </body> \n </html> ");
}
public   void   destroy(){}

}

//我的jsp文件,路径dopost\WebRoot\dopost.jsp这个可以显示
<%@   page   language= "java "   pageEncoding= "UTF-8 "%>

<html>
    <head>

<meta   http-equiv= "Content-Type "   content= "text/html;charset=UTF-8 ">
        <title> DoPost </title>
       
    </head>
   
    <body>
        <form   action= "/SerPost "   method= "post ">
        <p> Press   Submit   to   post   to   Servlet   SerPost </p>
        <p> name::: <input   type= "text "   name= "name "   value= " "> </p>
        <p> password::: <input   type= "text "   name= "password "   value= " "> </p>
        <p> <input   type= "submit "   name= "Submit "   value= "Submit ">
        <input   type= "reset "   value= "Reset "> </p>
        </form>
    </body>
</html>

//我的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> RequestInfo </servlet-name>
        <servlet-class> requestinfo.RequestInfo </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name> RequestInfo </servlet-name>
        <url-pattern> /RequestInfo </url-pattern>
    </servlet-mapping>

</web-app>


地址:http://127.0.0.1/SerPost,就有错误如下
HTTP   Status   404   -   /SerPost

--------------------------------------------

type   Status   report

message   /SerPost

description   The   requested   resource   (/SerPost)   is   not   available.


--------------------------------------------

Apache   Tomcat/5.5.16
各位大虾帮忙解决下,现在初学这个,所以弄不出来比较急啊!!!

[解决办法]
地址:http://127.0.0.1/SerPost,就有错误如下

这个有问题,应该是http://127.0.0.1/你的web项目名/SerPost
[解决办法]
up
[解决办法]
晕哦!!!就你们2个在这聊天啊!!
[解决办法]
建设楼主先学好原理,再用myeclipse自动生成servlet,这样出错的机会就比较少了。
[解决办法]
jefyjiang

赞一个
[解决办法]
request.setCharacterEncoding( "GB2312 ");设置编码

热点排行