This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Issue in web.xml mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Issue in web.xml mapping" Watch "Issue in web.xml mapping" New topic
Author

Issue in web.xml mapping

Jyothi Lalitha
Greenhorn

Joined: May 27, 2010
Posts: 7
Hi Friends

I have built a sample Dynamic web project (Test) in Eclipse IDE and the server is Tomcat.

I call a JSP through http://localhost:8081/Test/master/register/test.jsp which is to register user. I want to save the user information into DB using servlet.
So i gave the form action tag in JSP as follows <form name="input" method="post" action="JdbcServlet">

And in web.xml i have given the mapping as follows:
<servlet>
<servlet-name>registerServlet</servlet-name>
<servlet-class>com.pg.sebastian.sebastian.servlet.JdbcServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>registerServlet</servlet-name>
<url-pattern>/master/register/*</url-pattern>
</servlet-mapping>

But when i enter the info and click submit in JSP a blank page is appearing with URL as http://localhost:8081/Test/master/register/JdbcServlet

Please help me solve this. Can anyone figure out where exactly is the error?
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Are you sure, your servlet is excecuting correctly, check the server logs .. If you post your servlet code here, it will be easy to debug..


Regards, Prasad
SCJP 5 (93%)
Jyothi Lalitha
Greenhorn

Joined: May 27, 2010
Posts: 7
Its a simpel servlet. I haven't written any code in it actually.

Here is my servlet:

package com.pg.sebastian.sebastian.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.pg.sebastian.sebastian.utility.*;

public class JdbcServlet extends HttpServlet {
public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}
}

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507


But when i enter the info and click submit in JSP a blank page is appearing with URL as http://localhost:8081/Test/master/register/JdbcServlet


public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}
}


The answer for your question in the first quote, lies in the second quote, you are not doing anything inside doPost method of the servlet, so it is showing the blank page, then what else are you expecting the server to do..
Jyothi Lalitha
Greenhorn

Joined: May 27, 2010
Posts: 7
my worry is not about the wrong path the server is going to.

I have given the servlet path as "com.pg.sebastian.sebastian.servlet.JdbcServlet" in web.xml but the URL after submitting the JSP page is http://localhost:8081/Test/master/register/JdbcServlet.


Also its giving a 404 error at http://localhost:8081/Test/master/register/JdbcServlet.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

<form name="input" method="post" action="JdbcServlet">


the url the server is going to decide by the above action in the jsp page, here action is JdbcServlet, so the URL in the address bar will point to JdbcServlet..

please note that how you access the servlet is given in the servlet-mapping, servlet path has got nothing to do about it..
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

can you please post your directory structure here...
Jyothi Lalitha
Greenhorn

Joined: May 27, 2010
Posts: 7
So do i have to change the action tag of form or the servlet-mapping in web.xml?

Please suggest how i have to give it inorder to go to http://localhost:8081/Test/com/pg/sebastian/sebastian/servlet/JdbcServlet thsi location on clicking submit of JSP page.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

you have to change in both sides, change the action attribute in the jsp and servlet-mapping in web.xml to /com/pg/sebastian/sebastian/servlet/JdbcServlet
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
So i gave the form action tag in JSP as follows <form name="input" method="post" action="JdbcServlet">


This will post to http://localhost:8081/Test/JdbcServlet

my worry is not about the wrong path the server is going to.

I have given the servlet path as "com.pg.sebastian.sebastian.servlet.JdbcServlet" in web.xml but the URL after submitting the JSP page is http://localhost:8081/Test/master/register/JdbcServlet.


Also its giving a 404 error at http://localhost:8081/Test/master/register/JdbcServlet.


com.pg.sebastian.sebastian.servlet.JdbcServlet is the servlet class and not the servlet path. /master/register/* is the url pattern.
i hope you are not expecting any result by entering http://localhost:8081/Test/master/register/JdbcServlet from the browser as your have not overridden the doGet method

Prasad Krishnegowda wrote:you have to change in both sides, change the action attribute in the jsp and servlet-mapping in web.xml to /com/pg/sebastian/sebastian/servlet/JdbcServlet


/com/pg/sebastian/sebastian/servlet/JdbcServlet in url-pattern for web.xml
com/pg/sebastian/sebastian/servlet/JdbcServlet in action of form (note there is no leading /).

Jyoti please explain what are you trying to achieve clearly
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

com/pg/sebastian/sebastian/servlet/JdbcServlet in action of form (note there is no leading /).


yes, Amol, you are right. Sorry, didn't notice that...
Jyothi Lalitha
Greenhorn

Joined: May 27, 2010
Posts: 7
sorry friends there is some problem with the project setup that i received from the client.
The included file header of JSP has some errors. But when im executing the JSP file it was not showing those errors.

As the included files are not updated the problem has arised. Anyways sorry for the trouble and thanks for the help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue in web.xml mapping
 
Similar Threads
Tomcat unable to access the list of applications running through TomcatManager
modules and url
Server can't find my servlets
Servlet Mapping
Need a little more explanation on how to use urlmapper