Intellij+Tomcat,无法找到Servlet

stromlin 2016-04-24 02:04:55
我用IntellijU 2016编了一个Web应用,能访问到使用Tomcat最新版作为容器。能访问到默认的index.jsp,但是没办法访问到我编写的Servlet。请问各位是怎么回事,下面贴出相关信息:
在浏览器里面访问index.jsp所用路径:http://localhost:8080/index.jsp
在浏览器里面访问Servlet所用路径:http://localhost:8080/Servlet
项目有关设置贴图如下:
Project Structure:
1.Project:

2.Modules:

3.Artifacts:

Config:
1.Server:

2.Deployment:

项目结构以及Web.xml内容:

Servlet内容:
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 java.io.IOException;
import java.io.PrintWriter;

/**
* Created by Administrator on 2016/4/23.
*/
@WebServlet(name = "Servlet")
public class Servlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter printWriter=response.getWriter();
printWriter.println("Hello world");
}
}
...全文
401 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
街头小贩 2016-04-26
  • 打赏
  • 举报
回复
解决就好!用什么ide都是一样的,该注意的还是要注意。
stromlin 2016-04-25
  • 打赏
  • 举报
回复
谢谢版主的热情帮助,今天我找到了问题发生的原因。是我在配置JDK环境变量有误。大家以后在安装JDK时,无论是什么版本的JDK,大家都要仔细配置JDK的环境变量。
stromlin 2016-04-24
  • 打赏
  • 举报
回复
或者您留下您的邮箱,我把项目文件跟Tomcat打包发给您,您亲自试试?
stromlin 2016-04-24
  • 打赏
  • 举报
回复
很遗憾,即使是像您要求的这样做,也是没有用的,或许我应该改用Eclipse?
街头小贩 2016-04-24
  • 打赏
  • 举报
回复
如果你没有设置:tomcat的docBase或者没有把项目移到ROOT 中需要加项目名访问
stromlin 2016-04-24
  • 打赏
  • 举报
回复
但即使是去除Web..xml中的有关内容,用链接http://localhost:8080/Servlet还是不能访问到那个Servlet
街头小贩 2016-04-24
  • 打赏
  • 举报
回复
用了注解,就没有必要在web.xml中配置了,后者会覆盖掉类中的注解 web.xml中的servlet-class要用类全名

10,607

社区成员

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

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