Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 无法通过web.xml从index.html调用/映射到servlet-错误-404_Jsp_Servlets_Http Status Code 404 - Fatal编程技术网

Jsp 无法通过web.xml从index.html调用/映射到servlet-错误-404

Jsp 无法通过web.xml从index.html调用/映射到servlet-错误-404,jsp,servlets,http-status-code-404,Jsp,Servlets,Http Status Code 404,My index.html包含: ========================= I am creating a simple servlet on spring tool set / eclips but am failing to run it. on running the project, i am able to see my index home page html and click on the link for my jsp but fail to

My index.html包含: =========================

    I am creating a simple servlet on spring tool set / eclips but am failing to run it. on running 
    the project, i am able to see my index home page html and click on the link for my jsp but fail
    to get to the servlet link. i have attached the web.xml file which has the paths. i am 
    confused 

              1. what should i put  in servlet-name 
              2. what should i put  in servlet-class  
              3. what should i put  in url-patter 
              4. Is there is any relation between the index.html file and web.xml file.
              5. Finally what is my servlet-class supposed to hold?
<ul>
          <li>To a <a href="HellBoy.jsp">JSP page</a>.
          <li>To a <a href="/HellBoy">HelloWorldServlet</a>.
      </ul>
  • 到。
  • 到。
My web.xml包含: ======================

    I am creating a simple servlet on spring tool set / eclips but am failing to run it. on running 
    the project, i am able to see my index home page html and click on the link for my jsp but fail
    to get to the servlet link. i have attached the web.xml file which has the paths. i am 
    confused 

              1. what should i put  in servlet-name 
              2. what should i put  in servlet-class  
              3. what should i put  in url-patter 
              4. Is there is any relation between the index.html file and web.xml file.
              5. Finally what is my servlet-class supposed to hold?
<ul>
          <li>To a <a href="HellBoy.jsp">JSP page</a>.
          <li>To a <a href="/HellBoy">HelloWorldServlet</a>.
      </ul>

HellBoyServlet
com.ravi.servlet.HellBoy
HellBoServlet
/地狱
-----------------------------------------
  • servlet本身位于src/com.ravi.servlet/目录中,称为 HellBoy.java

  • 运行时,我会看到我的索引页,但我只能成功单击 href=“HellBoy.jsp” 指向servlet的链接,href=“/HellBoy”---F A I L S---giving error--HTTP Status 404-
    /地狱男孩/地狱

  • 很抱歉问了一个愚蠢的问题,我已经在网上搜索了一段时间了 整个星期的解决方案:(



servlet的URL应该是http://{host}/{appname}/Hell

如果您想从/HellBoy http://{host}/{appname}/HellBoy链接servlet访问,您应该

  <servlet>  
    <servlet-name>HellBoyServlet</servlet-name>
    <servlet-class>com.ravi.servlet.HellBoy</servlet-class>
 </servlet>


<servlet-mapping>
    <servlet-name>HellBoServlet</servlet-name>
    <url-pattern>/Hell</url-pattern>
</servlet-mapping>
    -----------------------------------------

HellBoServlet
/地狱男孩

您必须在web.xml中输入如下内容

<servlet-mapping>
    <servlet-name>HellBoServlet</servlet-name>
    <url-pattern>/HellBoy</url-pattern>
</servlet-mapping>

描述
HelloBoy
HelloBoy
com.abc.xyz.HelloBoy
HelloBoy
/HelloBoy
如果您在IDE中使用eclipse,然后直接创建新的servlet,它将自动在web.xml

index.html中创建所有条目
  • 不要在
    href
    属性中写入
    /HellBoy
  • 这里给出了与
    匹配的名称,在本例中,它是
    Hell
  • 无需更改
    web.xml
改为

      <servlet>
        <description> desc</description>
        <display-name>HelloBoy</display-name>
        <servlet-name>HelloBoy</servlet-name>
        <servlet-class>com.abc.xyz.HelloBoy</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>HelloBoy</servlet-name>
        <url-pattern>/HelloBoy</url-pattern>
      </servlet-mapping>

  • 我应该在servlet名称中输入什么

    必须在
    中匹配

    我应该在servlet类中放置什么

    servlet的完全限定名

    我应该在url模式中输入什么

    你想要的URL模式


    对于所有问题,请仔细阅读

    我尝试将url模式更改为HellBoy,但这也起到了作用-我刚刚了解到我在index.html中给出了斜杠/in,这也应该是HellBoy,所以你对我在web.xml中需要做的事情是正确的,但我也需要在index.html中做无斜杠-但非常感谢ch tom87416因为你让我想对了-我也很感激在servlet中我有一个Anotion(我听说这是一个新特性)这也调用了我创建的HellBoy servlet,不管index.htmlTanks Aniket中的匹配情况如何,地狱都不会工作。我能够让它工作,是的,上述答案进一步澄清了我的问题-appreciated@RaviSingh:不客气:)请接受作为答复,请参阅