-1

I am using Eclipse 4.3 kepler on Ubuntu 14.04 and using Apache tomcat 7 , I have successfully created .jsp and .html files in my project but I cannot Run a servlet, I have all jar files added in library . I have read every article on this error 404 ,which I am getting when I launch the following servlet

package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;




@WebServlet("/taxProcessor")
public class taxProcessor extends HttpServlet {
private static final long serialVersionUID = 1L;


/**
 * @see HttpServlet#HttpServlet()
 */
public taxProcessor() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String s=request.getParameter("t1");
    int i=Integer.parseInt(s);
    String s1=request.getParameter("t2");
    int a=Integer.parseInt(s1);
    int t=0;
    if(i>=500000)
    {
        t=i*(30/100);
    }else if(i>=300000)
    {
        t=i*(20/100);
    }else if(i>=200000)
    {
        t=i*(10/100);
    }
    if(a>=60)
    {
        t=t-(i*(10/100));
    }
PrintWriter out=response.getWriter();
out.println("Thank you for Visiting");
out.println("Your Tax Laibality is"+t+"\n");
out.close();
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
}

}

my web.xml file is

enter image description here

and all what I get is this enter image description here

Chinmaya B
  • 405
  • 1
  • 7
  • 21

2 Answers2

1

Instead of web.servlets.newtax.taxProcessor.java use web.servlets.newtax.taxProcessor in the web.xml

BTW your package name is servlet then how come you are giving web.servlets.newtax in the servlet-class tag

Example if in your eclipse your servlet class is in src/somePackageName/ServletClassName then your web.xml must contain the entries like this

    <servlet>
        <servlet-name>anyName</servlet-name>
        <servlet-class>somePackageName.ServletClassName</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>anyName</servlet-name>
        <url-pattern>/taxProcessor</url-pattern>
    </servlet-mapping>

One more thing as you specified the entries in the web.xml you can remove the annotation@WebServlet("/taxProcessor")

Finally run the servlet as http://localhost:8080/YourProjectName/taxProcessor

SparkOn
  • 8,806
  • 4
  • 29
  • 34
0

In web.xml give /newtax/..../taxProcessor .Dont give /newtax/..../taxProcessor.java and Check from browser by giving the url http://localhost:<port-number>/newtax.taxProcessor. Here give port number to your tomcat server port.Default is 8080

Nadendla
  • 712
  • 2
  • 7
  • 17