java - servlet3.1注解不生效
問題描述
我新建了個(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); }}
然后訪問http://localhost:8080/hello/H...顯示404
但訪問別的jsp頁面正常然后我加了個(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>
就能訪問了
但是我再新建個(gè)servlet文件,新建的卻還是無法訪問
@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):
問題解答
回答1:把你整個(gè)項(xiàng)目結(jié)構(gòu)發(fā)出來看下
回答2:開始放錯(cuò)圖片,以修正
相關(guān)文章:
1. bootstrp是col-md-12列的,只有col-md-10有內(nèi)容,可以讓沒有內(nèi)容的不占據(jù)位置嗎;2. java - 如何用圖畫的方式有效地表示多線程?3. thinkPHP5中獲取數(shù)據(jù)庫數(shù)據(jù)后默認(rèn)選中下拉框的值,傳遞到后臺(tái)消失不見。有圖有代碼,希望有人幫忙4. python - Fiddler+Android模擬器抓取app,json數(shù)據(jù)被加密了,如何解析?5. 在windows下安裝docker Toolbox 啟動(dòng)Docker Quickstart Terminal 失??!6. python 3.4 error: Microsoft Visual C++ 10.0 is required7. html5 - 剛接觸H5,為什么我覺得很多標(biāo)簽都沒什么用呢?8. 我的怎么不顯示啊,話說有沒有QQ群什么的9. android - 請問一下 類似QQ音樂底部播放 在每個(gè)頁面都顯示 是怎么做的?10. html5 - 現(xiàn)在前端設(shè)備和網(wǎng)速都提高了,為什么要用服務(wù)器端渲染?
