servlet程序部署到tomcat上为什么总是连接显示404找不到资源

lecky-fu 2014-10-15 04:41:07

写的servlet程序部署到tomcat服务器上之后,在浏览器里打开总是显示资源无法获取,图片是工程项目截图,Eclipse开发的。请教一下是什么问题

下面是web.xml文件配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>coreServlet</servlet-name>
<servlet-class>
org.liufeng.course.servlet.CoreServlet
</servlet-class>
</servlet>

<!-- url-pattern中配置的/coreServlet用于指定该Servlet的访问路径 -->
<servlet-mapping>
<servlet-name>coreServlet</servlet-name>
<url-pattern>/coreServlet</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
...全文
2406 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
已矣 2016-02-27
  • 打赏
  • 举报
回复
我看了这么个博客,可能是eclipse启动tomcat时默认参数问题 http://blog.sina.com.cn/s/blog_8020e41101014lvu.html
已矣 2016-02-27
  • 打赏
  • 举报
回复
我遇到同样问题,问题是这样的,当我运行我的servlet程序时,我在浏览器访问webapp文件夹下其他所有的资源都是404错误,包括默认主页index都是404,当我把程序关了,再手动启动tomcat,一切又正常了,url是保证没有错误的,难道是端口冲突么?就是要么运行servlet,要么访问资源,不可兼得,这是什么鬼?
qq_28506375 2016-01-30
  • 打赏
  • 举报
回复
还没结贴, <welcome-file-list> <welcome-file>coreServlet</welcome-file> </welcome-file-list>
lecky-fu 2014-10-15
  • 打赏
  • 举报
回复
class的输出路径是在build文件夹,这是用Eclipse开发的。 CoreServlet代码 package org.liufeng.course.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; import org.liufeng.course.service.CoreService; import org.liufeng.course.util.SignUtil.checkSignature.SignUtil; /** * Servlet implementation class CoreServlet */ @WebServlet("/CoreServlet") public class CoreServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * Default constructor. */ public CoreServlet() { // 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 // my // 微信加密签名 String signature = request.getParameter("signature"); // 时间戮 String timestamp = request.getParameter("timestamp"); // 随机数 String nonce = request.getParameter("nonce"); // 随机字符串 String echostr = request.getParameter("echostr"); PrintWriter out = response.getWriter(); // 通过检验 signature 对请求进行校验,若校验成功则原样返回 echostr,表示接入成功,否则接入失败 if(SignUtil.checkSignature(signature, timestamp, nonce)){ out.print(echostr); } out.close(); out = null; } /** * 处理微信服务器发来的消息 * 从微信公众平台接口消息指南中可以了解到,当用户向公众帐号发消息时,微信服务器会将消息通过POST方式提交给我们 * 在接口配置信息中填写的URL,而我们就需要在URL所指向的请求处理类CoreServlet的doPost方法中接收消息、处理消息 * 和响应消息。 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub // 将请求、响应的编码均设置为UTF-8(防止中文乱码) //微信服务器POST消息时用的是UTF-8编码,在接收时也要用同样的编码,否则中文会乱码; request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); // 调用核心业务类接收消息、处理消息 String respMessage = CoreService.processRequest(request); // 响应消息 //调用response.getWriter().write()方法将消息的处理结果返回给用户 PrintWriter out = response.getWriter(); out.print(respMessage); out.close(); } } l
yflyers 2014-10-15
  • 打赏
  • 举报
回复
看看class输出路径是否正确
shixitong 2014-10-15
  • 打赏
  • 举报
回复
没看出哪边有问题, 顺便把org.liufeng.course.servlet.CoreServlet 这个servlet也贴出来看看 对了,后台还报错吗/
bfas2010 2014-10-15
  • 打赏
  • 举报
回复
http://www.hbstbc.org/weixin 你的这个路径能访问不?若不能,就是weixin不是工程的路径。选中项目Alt+enter, 输入web。点击查看context-root.将这个值替换weixin. 如能访问。配置的ServletClass找不到,看看名字是否一样。
lecky-fu 2014-10-15
  • 打赏
  • 举报
回复
http://www.hbstbc.org/weixin/coreServlet 访问路径
shixitong 2014-10-15
  • 打赏
  • 举报
回复
访问路径贴出来看看

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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