1

I am getting HTTP Status 404 when i call Servlet from JSP page.

Here is web.xml :

<servlet>
    <servlet-name>Register</servlet-name>
    <servlet-class>servlets.dataio.registration.Register</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Register</servlet-name>
    <url-pattern>/Register</url-pattern>
</servlet-mapping>

Here is effective code of JSP:

<form name="admin-form" action="Register" method="POST"> 

Error message:

HTTP Status 404 - Not Found

type Status report

message: Not Found

description: The requested resource is not available.

Directory structure is:

Web Pages --> Pages --> Registration --> registerpage.jsp

I have tried Clean and Building project. I am using NetBeans IDE and GlassFish server

Not a bug
  • 4,286
  • 2
  • 40
  • 80
Malwinder Singh
  • 6,644
  • 14
  • 65
  • 103

3 Answers3

1

Try:

action="../../Register"

To make your page relative to where the Servlet is.

../ means one directory up. And based on the directory structure you've posted, it's two folders down under the Web Pages so you'll need two ../ to make it relative to where your Servlet is, which is, based <url-pattern>/Register</url-pattern> meaning just under Web Pages

lxcky
  • 1,668
  • 2
  • 13
  • 26
1

The action attribute is using by default relative path, so if your jsp is available at http://yourHost/yourApp/pathToJsp/registerpage.jsp then your relative servlet path is http://yourHost/yourApp/pathToJsp/Register which is not correct.

You have two choices:

  • use relative path like J.Lucky suggested - but its error prone, as you have to fix it in every jsp, or if you move jsp in you directory structure
  • use absoulute path - start with / - but you need to include your context-root name, like this - /yourContext/Register. If you want to avoid hard coding context root you can use request.getContextPath() method, like this action='<%=request.getContextPath()%>/Register'
Gas
  • 17,601
  • 4
  • 46
  • 93
0

try action="/Register"

and this line is 'cause message must be at least 30 chars

p_xr
  • 59
  • 3