81,122
社区成员




<servlet>
<servlet-name>helloServlet</servlet-name>
<servlet-class>com.example.myWebsite.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
package com.example.myWebsite;
import java.io.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
private String message;
public void init(ServletConfig config)throws ServletException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
String name = request.getParameter("name");
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<html>" +
"<head><title>Servlet运行</title></head>" +
"<body><h2>您好"+name+"</h2></body>" +
"</html");
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
doGet(request, response);
}
public void destroy() {
}
}
<%--
Created by IntelliJ IDEA.
User: luo'xin
Date: 2021/5/9
Time: 23:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>欢迎</title>
</head>
<body>
<h2>Servlet</h2>
<form method="post" action="/hello">
姓名:<input name="name" type="text">
<button type="submit">提交</button>
</form>
</body>
</html>
就是404找不到页面 [quote=引用 5 楼 afrgefitx 的回复:]你把错误代码贴出来啊
就是404找不到页面 你把错误代码贴出来啊
就是404找不到页面 [quote=引用 6 楼 Little BigUs 的回复:][quote=引用 5 楼 afrgefitx 的回复:]你把错误代码贴出来啊
就是404找不到页面 [quote=引用 7 楼 afrgefitx的回复:][quote=引用 6 楼 Little BigUs 的回复:][quote=引用 5 楼 afrgefitx 的回复:]你把错误代码贴出来啊
就是404找不到页面 [quote=引用 5 楼 afrgefitx 的回复:]你把错误代码贴出来啊
你把错误代码贴出来啊
java 方法中 写了 @WebServlet(name = "helloServlet", value = "/hello-servlet") 可以不用web。xml中加 <servlet> <servlet-name>helloServlet</servlet-name> <servlet-class>com.example.myWebsite.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>helloServlet</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping>