简体   繁体   English

在表单动作中使用Servlet时Servlet路径错误

[英]Wrong Servlet path while using Servlet in form's action

I am trying to send data to a Login servlet using a form in jsp. 我正在尝试使用jsp中的表单将数据发送到Login servlet。 My jsp and my servlet are in different folders. 我的jsp和servlet位于不同的文件夹中。 Parent folder is "mybay". 父文件夹是“ mybay”。 In it there is a folder which is named javaServlets and another one named main_pages. 其中有一个名为javaServlets的文件夹和另一个名为main_pages的文件夹。 In javaServlets there are LoginServlet.java and LoginServlet.class. 在javaServlets中,有L​​oginServlet.java和LoginServlet.class。 In main_pages there is login.jsp. 在main_pages中有login.jsp。 When i submit username and password i see that tomcat stays in main_pages and does't look in javaServlets folder. 当我提交用户名和密码时,我看到tomcat停留在main_pages中并且不在javaServlets文件夹中。 I don't know if my web.xml is wrong. 我不知道我的web.xml是否错误。

HTTP Status 404 - /mybay/main_pages/LoginServlet //here i see that the path is wrong. HTTP状态404-/ mybay / main_pages / LoginServlet //这里我看到路径错误。 The right path is /mybay/javaServlets/LoginServlet 正确的路径是/ mybay / javaServlets / LoginServlet

Can you help? 你能帮我吗?

Here is my code: 这是我的代码:

login.jsp login.jsp

             <form action="LoginServlet" method="post">
                <p>
                <label id="upodeiksh">username</label>
                <br />
                <input type="text" name="username" id="koutaki" required/>
                </p>
                <br />
                <p>
                <label id="upodeiksh">password</label>
                <br />
                <input type="password" name="password" id="koutaki" required/>
                </p>
                <br />
                <input type="submit" name="upload" value="Connect" id="submit_button"/>
            </form>

web.xml web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>test_pages</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>LoginServlet</servlet-name>  
    <servlet-class>javaServlets.LoginServlet</servlet-class>  
  </servlet> 

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

</web-app>

尝试在servletaction的前面添加“ /”

<form action="/LoginServlet" method="post">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM