0

I am trying to send data to a Login servlet using a form in jsp. My jsp and my servlet are in different folders. Parent folder is "mybay". In it there is a folder which is named javaServlets and another one named main_pages. In javaServlets there are LoginServlet.java and LoginServlet.class. In main_pages there is login.jsp. When i submit username and password i see that tomcat stays in main_pages and does't look in javaServlets folder. I don't know if my web.xml is wrong.

HTTP Status 404 - /mybay/main_pages/LoginServlet //here i see that the path is wrong. The right path is /mybay/javaServlets/LoginServlet

Can you help?

Here is my code:

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

<?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>

1 Answers1

0

try to add "/" infront of the servletaction

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