赞
踩
由于社区版直接阉割掉了web功能,所以只能自己配置了,欸,真是百因必有果,这是白嫖党最难过的一天,但是白嫖党总能想办法。。。
话不多说,直接开始
具体流程为:
链接:
选和自己计算机匹配的文件下载
下载完自己找个地方解压就行
然后是创建普通maven项目
直接开main文件夹下创建如下结构
在test下添加一个resources
重点来了
配置完要引入依赖
接着
最后编写web.xml文件
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app id="WebApp_ID" version="4.0"
- xmlns="http://xmlns.jcp.org/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
- http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
- <display-name>xss</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- </web-app>

在main,java文件夹下写个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;
-
- @WebServlet(name = "Servlet",urlPatterns = "/test")
- public class Servlet extends HttpServlet {
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- resp.getWriter().write("this is my first Servlet");
- }
- }
成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。