java - servlet3.1注解不生效
問題描述
我新建了個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); }}
然后訪問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)求解注解為什么不能用啊
項(xiàng)目結(jié)構(gòu):
問題解答
回答1:把你整個項(xiàng)目結(jié)構(gòu)發(fā)出來看下
回答2:開始放錯圖片,以修正
相關(guān)文章:
1. HTML5不支持frameset一般怎么解決?2. javascript - Vue的計(jì)算屬性底層依賴原理是怎么樣?3. javascript - jquery怎么給select option一個點(diǎn)擊時(shí)觸發(fā)的事件,如圖 如果選擇自定義觸發(fā)一個時(shí)間?4. 網(wǎng)頁爬蟲 - python爬蟲用BeautifulSoup爬取<s>元素并寫入字典,但某些div下沒有這一元素,導(dǎo)致自動寫入下一條,如何解決?5. 百度地圖api - Android百度地圖SDK,MapView上層按鈕可見卻不可觸,怎么解決?6. mysql 獲取時(shí)間函數(shù)unix_timestamp 問題?7. html5 - canvas中的mousedrag事件,為什么鼠標(biāo)拖出canvas,然后再次移入canvas,drag事件還觸發(fā)8. 新入手layuiadmin,部署到tp中。想用php自已寫一個后臺管理系統(tǒng)。9. javascript - react 組件 使用super()報(bào)錯10. javascript - es6擴(kuò)展運(yùn)算符...的問題
