We help IT Professionals succeed at work.
Get Started

Servlet is calling the wrong class

597 Views
Last Modified: 2013-12-15
I have attached my project, my problem is my project is calling my servlet from the wrong path, Project/html/AddData, for example this however is wrong.

I was intially calling my servlet in the default package without a web.xml file, the form gave the address /Project/servlet/AddData. This worked.

I then changed it to the package to com.project.controller, it then stopped working. I assumed this was due to the lack of a deployment descriptor "web.xml" file. I added this file, changed the form address to "AddData". This still isnt working, I am missing a step or have I made a mistake somewhere. I attached the relevant files
<HTML>
<HEAD>
<TITLE>Registration Form</TITLE>
<link rel="stylesheet" type="text/css" href="/Project/html/Style.css"/>
</HEAD>
 
<BODY>

<FORM METHOD="POST" 
   ACTION="AddData" 
   name="myform"> 

<H3>Choose and Insert GPSData:</H3>
 

<SELECT NAME = "gpsdata">
        <OPTION>$GPRMC,194932.530,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*7A</OPTION>
        <OPTION>$GPRMC,194934.530,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*7C</OPTION>
        <OPTION>$GPRMC,194936.530,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*7E</OPTION>
        <OPTION>$GPRMC,194938.529,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*78</OPTION>
        <OPTION>$GPRMC,194940.529,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*77</OPTION>
        <OPTION>$GPRMC,194942.528,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*74</OPTION>
        <OPTION>$GPRMC,194944.528,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*72</OPTION>
        <OPTION>$GPRMC,194946.528,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*70</OPTION>
        <OPTION>$GPRMC,194948.527,A,5049.5330,N,00109.9218,W,0.00,131.16,170206,,,D*71</OPTION>
        <OPTION>$GPRMC,194950.527,A,5049.5330,N,00109.9217,W,0.00,131.16,170206,,,D*77</OPTION>
        <OPTION>$GPRMC,194952.527,A,5049.5329,N,00109.9217,W,0.00,131.16,170206,,,D*7D</OPTION>
        <OPTION>$GPRMC,194954.526,A,5049.5329,N,00109.9217,W,0.00,131.16,170206,,,D*7A</OPTION>
        <OPTION>$GPRMC,194956.526,A,5049.5329,N,00109.9217,W,0.00,131.16,170206,,,D*78</OPTION>
        </SELECT>
        
  <BR><INPUT TYPE="submit" value="Submit Form"> 
  <INPUT TYPE="reset" value="Clear Form">
 
 
 
</FORM>
</BODY>
</HTML>

Open in new window

<?xml version = '1.0'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, 
Inc.//DTD Web Application 2.2//EN" 
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
   <display-name>Deployment Descriptor</display-name>
   <description>Servlet Examples for EE557</description>
	 <servlet>
           <servlet-name>AddData</servlet-name>
           <servlet-class>com.project.controller.AddData</servlet-class>
	 </servlet>
	 <servlet>
           <servlet-name>SelectTable</servlet-name>
           <servlet-class>com.project.controller.SelectTable</servlet-class>
	 </servlet>
	 <servlet>
           <servlet-name>ViewTable</servlet-name>
           <servlet-class>com.project.controller.ViewTable</servlet-class>
	 </servlet>
 </web-app>

Open in new window

package com.project.controller;
import java.io.*;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;

public class AddData extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	DBManager a = new DBManager();

	public void doPost(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException 
	{
		res.setContentType("text/html");
		String NMEAData = req.getParameter("gpsdata");
		GPSData b = a.ParseData(NMEAData);
		System.out.println(b.getLong_Dir());
		a.Connect();
		a.Insert(b);
		a.Disconnect();
		res.sendRedirect("/StudentRegistration/index.html");
		
		//System.out.println(b.getLat());
			
		}

	}

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE