java - servlet3.1注解不生效
問題描述
我新建了個servlet項目:
package hello;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Servlet implementation class HelloServlet */@WebServlet('/Hello')public class HelloServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * Default constructor. */ public HelloServlet() {// 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 stubresponse.getWriter().append('Served at: ').append(request.getContextPath()); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response); }}
然后訪問http://localhost:8080/hello/H...顯示404
但訪問別的jsp頁面正常然后我加了個web.xml文件:
<?xml version='1.0' encoding='UTF-8'?><web-app xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://xmlns.jcp.org/xml/ns/javaee' xsi:schemaLocation='http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd' version='3.1'></web-app>
就能訪問了
但是我再新建個servlet文件,新建的卻還是無法訪問
@WebServlet('/World')public class WorldServlet extends HttpServlet {
為什么會這樣啊?難道不能用注解了?我用的tomcat 8.5 , Java 1.8 , servlet 3.1 , eclipse 4.6.0 (Neon)求解注解為什么不能用啊
項目結構:
問題解答
回答1:把你整個項目結構發出來看下
回答2:開始放錯圖片,以修正
相關文章:
1. 一個mysql聯表查詢的問題2. 運行python程序時出現“應用程序發生異常”的內存錯誤?3. html5 - iOS的webview加載出來的H5網頁,怎么修改html標簽select的樣式字體?4. java-se - 正在學習Java SE,為什么感覺學習Java就是在學習一些API。5. python 如何實現PHP替換圖片 鏈接6. python如何不改動文件的情況下修改文件的 修改日期7. 主從備份 - 跪求mysql 高可用主從方案8. javascript - git clone 下來的項目 想在本地運行 npm run install 報錯9. mysql主從 - 請教下mysql 主動-被動模式的雙主配置 和 主從配置在應用上有什么區別?10. mysql - 一個表和多個表是多對多的關系,該怎么設計
