到底要怎么才能在浏览器访问Servlet

李狗剩 2014-07-31 05:13:54
用myEclipse创建了一个web项目名称叫做webDemo,然哦后在src中创建一个web包,然后就在里面直接创建一个Servlet,myEclipse就会自动帮我配置好web.xml,然后我就直接把生成的文件夹给复制到tomcat中的webapps中,但是无论如何都访问不了Servlet,到底是为什么!!!!!
...全文
4416 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
文哥xxx 2014-08-05
  • 打赏
  • 举报
回复
引用 15 楼 yongcan10529 的回复:
引用 13 楼 guo315648865 的回复:
项目右键export打成war包,放到tomcat的webapp目录下
右键没有export啊
是点击你的 项目 右键 啊
李狗剩 2014-08-04
  • 打赏
  • 举报
回复
引用 13 楼 guo315648865 的回复:
项目右键export打成war包,放到tomcat的webapp目录下
右键没有export啊
文哥xxx 2014-08-01
  • 打赏
  • 举报
回复
项目右键export打成war包,放到tomcat的webapp目录下
S117 2014-08-01
  • 打赏
  • 举报
回复
你要打成war包,放到tomcat的webapp目录下
tony4geek 2014-08-01
  • 打赏
  • 举报
回复
把你的项目打成包,然后放tomact下
缘与我无缘 2014-08-01
  • 打赏
  • 举报
回复
引用 9 楼 yongcan10529 的回复:
引用 6 楼 wangjianwei_ 的回复:
没有代码,无法查找原因
上面那些不是代码?
代码没有问题,运行结果 This is class web.First, using the GET method 检查下自己的运行环境
niuyongzljtoo 2014-08-01
  • 打赏
  • 举报
回复
你没有发布成功,看看你MYECLIPSE对应的TOMCAT目录下SERVLET的CLASS文件是否生成了,在MYECLIPSE里面重新发布一下
李狗剩 2014-07-31
  • 打赏
  • 举报
回复
引用 6 楼 wangjianwei_ 的回复:
没有代码,无法查找原因
上面那些不是代码?
李狗剩 2014-07-31
  • 打赏
  • 举报
回复
引用 4 楼 w405112941 的回复:
Tomcat启动了吗?启动了以后浏览器输入-----localhost:8080/你的项目名/First 你的端口号是多少就把8080改成多少,如果你的 Web Context-root设置的是/,那就把上面的“你的项目名去掉”
我访问我这个工程的index.jsp就能成功,但是访问Servlet就是无论如何都是无法成功的
李狗剩 2014-07-31
  • 打赏
  • 举报
回复
引用 3 楼 magi1201 的回复:
工程 右键 export war 包 到 tomcat 的webapps 下面 ,tomcat 启动成功 http://localhost:8080/webDemo/servlet/First 红色部分根据实际情况更改
右键没有export war 这个选项
缘与我无缘 2014-07-31
  • 打赏
  • 举报
回复
没有代码,无法查找原因
shixitong 2014-07-31
  • 打赏
  • 举报
回复
把访问路径贴出来看看,是不是没加servlet
The_end90 2014-07-31
  • 打赏
  • 举报
回复
Tomcat启动了吗?启动了以后浏览器输入-----localhost:8080/你的项目名/First 你的端口号是多少就把8080改成多少,如果你的 Web Context-root设置的是/,那就把上面的“你的项目名去掉”
姜小白- 2014-07-31
  • 打赏
  • 举报
回复
工程 右键 export war 包 到 tomcat 的webapps 下面 ,tomcat 启动成功 http://localhost:8080/webDemo/servlet/First 红色部分根据实际情况更改
李狗剩 2014-07-31
  • 打赏
  • 举报
回复
package web; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class First extends HttpServlet { /** * Constructor of the object. */ public First() { super(); } /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } }
李狗剩 2014-07-31
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <servlet-name>First</servlet-name> <servlet-class>web.First</servlet-class> </servlet> <servlet-mapping> <servlet-name>First</servlet-name> <url-pattern>/servlet/First</url-pattern> </servlet-mapping> </web-app>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧