enthusiastic
enthusiastic

Reputation: 1702

Servlets-requested resource not found

I have index.jsp from which I get the parameters to servlet LoginServlet.java The servlet is under package dao.

<form name="LoginForm" method="post" action="dao/LoginServlet">

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Chat</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>LoginServlet</display-name>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>dao.LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>Login</url-pattern>
  </servlet-mapping>
</web-app>

When I run the JSP page I can see it but I get an error telling

The requested resource (dao/LoginServlet) is not available

Can anyone point out wat is the problem?

Upvotes: 0

Views: 7769

Answers (1)

BalusC
BalusC

Reputation: 1108732

The form action should point to the servlet URL as specified in <url-pattern> entry of its <servlet-mapping> in web.xml. You have declared the servlet to listen on Login, but this is actually invalid. It should start with a slash.

<url-pattern>/Login</url-pattern>

This way it listens on http://localhost:8080/yourcontextname/Login.

Then you can just let the form action point to that URL (assuming that the JSP file isn't placed in a subfolder of your webapp context).

<form action="Login" method="post">

See also:

Upvotes: 3

Related Questions