• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issue in web.xml mapping

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Jyothi Lalitha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you please post your directory structure here...
 
Jyothi Lalitha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic