当前位置:首页 » 业界相关

Servlet怎么运行不了,另外还有一些小问题。

 Advertisement:

热门软件下载:


初学servlet,写了个最简单的servlet,可就是运行不了,  
  tomcat运行良好,我的目录结构是:在examples下创建一  
  个目录,名为myservlet,里面有web-inf文件夹和welcomeservlet.html  
  文件,web-inf文件夹里有classes文件夹和web.xml文件,  
  classes文件夹里是welcomeservlet.java文件,我把几个  
  文件内容都写在下面了,帮我看看哪里有错啊,谢谢。  
  再问一个,什么是:struts啊,和mvc有什么区别吗,  
  是一种概念还是一个软件,谢谢。下面是文件。  
  ========welcomeservlet.java============================  
  package   com.yangjun;  
  import   java.io.*;  
  import   javax.servlet.*;  
  import   javax.servlet.http.*;  
  public   class   welcomeservlet   extends   httpservlet  
  {  
  protected   void   doget(httpservletrequest   request,  
      httpservletresponse   response)throws   servletexception,ioexception  
  {  
  response.setcontenttype("text/html");  
  printwriter   out=response.getwriter();  
  out.println("<html>");  
  out.println("<head>");  
  out.println("<title>my   first   serlver</title>");  
  out.println("</head>");  
  out.println("<body>");  
  out.println("<h1>welcome   servlet</h1>");  
  out.println("</body>");  
  out.println("</html>");  
  out.close();  
  }  
  }  
  ===========web.xml=========================================  
  <?xml   version="1.0"   encoding="gb2312"?>  
  <web-app>  
      <display-name>  
          advanced   java   how   to   program   jsp   and   servlet   examples.  
      </display-name>  
      <description>  
          thie   is   the   web   application   on   which   demonstrate  
          our   jsp   and   servlet   examples.  
      </description>  
   
      <servlet>  
          <servlet-name>welcome1</servlet-name>  
          <servlet-class>com.yangjun.welcomeservlet</servlet-class>  
      </servlet>  
      <servlet-mapping>  
          <servlet-name>welcome1</servlet-name>  
          <url-pattern>/welcome1</url-pattern>  
      </servlet-mapping>  
  </web-app>  
  ================welcomeservlet.html=======================  
  <html>  
  <head>  
  <title>serlvet</title>  
  </head>  
  <body>  
      <form   action="/myservlet/welcome1"   method="get">  
          <p>click   the   button   to   invoke   the   servlet.  
              <input   type="submit"   value="get   html   document"/>  
          </p>  
      </form>  
  </body>  
  </html>  
  ===========================================================  
  多谢了!

推荐阅读

  • IN-STAT:图像传感器市场增长势头继续壮大 [详细内容]
  • 中广网、光通启用新防盗号系统 [详细内容]
  • K606实际使用中的一些问题 [详细内容]
  • 华山论剑 二十款发烧级电阻无敌试听 [详细内容]
  • 北邮教授透露中国3G手机启用新号段 [详细内容]
  • 初识夏新M350——外观第一感 [详细内容]
  • 全球半导体厂排名台积电AMD名次上升 [详细内容]
  • 网友回答:
    网友:keyong19ryry

    server.xml有配置吗?  
      你的myservlet是一个新应用,要重新配置  
     

    网友:nettman

    不是配置的问题,是程序的问题!

    网友:nettman

    ================welcomeservlet.html=======================  
      <html>  
      <head>  
       
      <title>serlvet</title>  
      </head>  
      <body>  
          <form   action="虚拟目录/servlet/com.yangjun.welcomeservlet"   method="get">  
              <p>click   the   button   to   invoke   the   servlet.  
                  <input   type="submit"   value="get   html   document"/>  
              </p>  
          </form>  
      </body>  
      </html>

    网友:nettman

    主要是所访问的servlet程序在package   com.yangjun中。

    网友:whatwhynot

    struts是用来实现mvc的

    网友:gaojunbo

    package   com.yangjun;  
      你的servlet有包,所以必须在webapps下建立相应的目录.  
      webapps  
            com  
                yangjun  
                      web-inf  
                            classes  
                                    welcomeservlet.class  
                     
     

    .  

    相关评论

    Login