0

I have this form declaration in my JSP page:

<form name="login" method="post" action="loginServlet"> 

Assume that the servlet is appropriately declared in the web.xml file; with this pattern <url-pattern>/loginServlet</url-pattern>;

this servlet contains a doPost method.

But what happens is that when I press the button associated to the login form, the server complains that this servlet is not found. What kind of path should I use in order to make it work?

This is the folder structure of my project:

-Project0
   -jsppages
      login.jsp
   +htmlpages
   -WEB-INF
      -classes 
          LogIn.class

I guess there's a problem with the path. How could I fix this. Thank you!

Edit: the web.xml contains exactly this referred to my servlet:

  <servlet>
      <servlet-name>LogInServlet</servlet-name>
      <servlet-class>LogIn.class</servlet-class>
   </servlet>

   <servlet-mapping>
      <servlet-name>LogInServlet</servlet-name>
      <url-pattern>/loginServlet</url-pattern>
   </servlet-mapping>

SOLVED:

When calling the action releted to the form, it was necessary to go out of the JSP folder in my project folder by using the path ../loginsServlet so it becomes like this.

<form name="login" method="post" action="../loginServlet"> 
Matt
  • 773
  • 2
  • 15
  • 32

2 Answers2

0

check your web.xml which is present in WEB-INF directory

below is sample

<web-app>
<display-name>HelloWorld Application</display-name>
<servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>SERVLET CLASS NAME WITH PACKE</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/loginServlet</url-pattern>
</servlet-mapping>

and change your action value

<form name="login" method="post" action="./loginServlet"> 
KhAn SaAb
  • 5,248
  • 5
  • 31
  • 52
0

add this to your web.xml file . your page will map to your Servlet

<servlet>
    <servlet-name>loginservlet</servlet-name>
    <servlet-class>package.LogIn</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>loginservlet</servlet-name>
    <url-pattern>/loginServlet</url-pattern>

Note:- Please Put the complete package name (eg com.login.ClassName) before your class name.

Thank You

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52