java - servlet3.1注解不生效
問(wèn)題描述
我新建了個(gè)servlet項(xiàng)目:
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); }}
然后訪問(wèn)http://localhost:8080/hello/H...顯示404
但訪問(wèn)別的jsp頁(yè)面正常然后我加了個(gè)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>
就能訪問(wèn)了
但是我再新建個(gè)servlet文件,新建的卻還是無(wú)法訪問(wèn)
@WebServlet('/World')public class WorldServlet extends HttpServlet {

為什么會(huì)這樣啊?難道不能用注解了?我用的tomcat 8.5 , Java 1.8 , servlet 3.1 , eclipse 4.6.0 (Neon)求解注解為什么不能用啊
項(xiàng)目結(jié)構(gòu):
問(wèn)題解答
回答1:把你整個(gè)項(xiàng)目結(jié)構(gòu)發(fā)出來(lái)看下
回答2:開(kāi)始放錯(cuò)圖片,以修正
相關(guān)文章:
1. javascript - sublime快鍵鍵問(wèn)題2. javascript - immutable配合react提升性能?3. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽(tīng)數(shù)據(jù)變化4. 配置Apache時(shí),添加對(duì)PHP的支持時(shí)語(yǔ)法錯(cuò)誤5. css - 寫(xiě)頁(yè)面遇到個(gè)布局問(wèn)題,求大佬們幫解答,在線等,急!~6. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問(wèn)7. javascript - 移動(dòng)端上不能實(shí)現(xiàn)拖拽布局嗎?8. phpstudy8.1支持win11系統(tǒng)嗎?9. 實(shí)現(xiàn)bing搜索工具urlAPI提交10. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問(wèn)?

網(wǎng)公網(wǎng)安備