赞
踩



4、配置Tomcat路径

选择路径点击ok
然后应用Tomcat点击确定
这样我们的Tomcat就配置好了


这时候我们创建的模板里会出现一个名为Web的文件夹就表示成功了




实现Servlet接口代码如下:
- import javax.servlet.*;
- import java.io.IOException;
-
- public class Login implements Servlet {
- @Override
- public void init(ServletConfig servletConfig) throws ServletException {
-
- }
-
- @Override
- public ServletConfig getServletConfig() {
- return null;
- }
-
- @Override
- public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
-
- }
-
- @Override
- public String getServletInfo() {
- return null;
- }
-
- @Override
- public void destroy() {
-
- }
- }


代码如下:
- <%--
- Created by IntelliJ IDEA.
- User: DELL
- Date: 2023/2/13
- Time: 19:45
- To change this template use File | Settings | File Templates.
- --%>
- <%@ page contentType="text/html;charset=UTF-8" language="java" %>
- <html>
- <head>
- <title>Java Web</title>
- </head>
- <body>
- <a href="login">登录</a>
- </body>
- </html>

- <?xml version="1.0" encoding="UTF-8"?>
- <web-app 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"
- version="4.0">
- <!-- 配置servlet类 -->
- <servlet>
- <!--起别名-->
- <servlet-name>login</servlet-name>
- <!-- servlet类所在的位置:类的全类名就是 包名.类名 -->
- <servlet-class>Login</servlet-class>
- </servlet>
-
- <!-- Servlet类的映射:Servlet用来处理哪个请求 -->
- <servlet-mapping>
- <servlet-name>login</servlet-name>
- <url-pattern>/login</url-pattern>
- </servlet-mapping>
- </web-app>



Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。