在Eclipse中找不到Java Servlet错误404
我在Ubuntu 14.04上使用Eclipse 4.3 kepler并使用Apache tomcat 7,我已经在项目中成功创建了.jsp和.html文件,但是我无法运行servlet,我在library中添加了所有jar文件.我已经阅读了有关此错误404的每篇文章,当我启动以下servlet
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
}
}
我的web.xml文件是
my web.xml file is
我所得到的就是这个
而不是 web.servlets.newtax.taxProcessor.java
使用 web.servlets.newtax.taxProcessor
在web.xml中
Instead of web.servlets.newtax.taxProcessor.java
use web.servlets.newtax.taxProcessor
in the web.xml
顺便说一句,您的包名称是 servlet
,那么您如何在servlet-class标记中给出 web.servlets.newtax
BTW your package name is servlet
then how come you are giving web.servlets.newtax
in the servlet-class tag
例如,如果在日食中servlet类位于 src/somePackageName/ServletClassName
中,则您的web.xml必须包含这样的条目
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>
在web.xml中指定条目的另一件事是,您可以删除注释 @WebServlet("/taxProcessor")
One more thing as you specified the entries in the web.xml you can remove the annotation@WebServlet("/taxProcessor")
最后以 http://localhost:8080/YourProjectName/taxProcessor