package com.xxxx.servlet;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
/*创建Servlet类*/
@WebServlet(name = "TestServlet01", value = "/TestServlet01")
public class TestServlet01 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.xxxx.servlet;
public class Student {
private String name;
private int age;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>学生信息</title>
</head>
<body>
<jsp:useBean id="student" class="com.xxxx.Student"></jsp:useBean>
<jsp:setProperty name="student" property="name" value="小明"></jsp:setProperty>
<jsp:setProperty name="student" property="age" value="18"></jsp:setProperty>
<jsp:setProperty name="student" property="sex" value="男"></jsp:setProperty>
<div>
<ul>
<li>
姓名:<jsp:setProperty name="student" property="name"></jsp:setProperty>
</li>
<li>
年龄:<jsp:setProperty name="student" property="age"></jsp:setProperty>
</li>
<li>
性别:<jsp:setProperty name="student" property="sex"></jsp:setProperty>
</li>
</ul>
</div>
</body>
</html>
3:
package com.xxxx.servlet;
import jakarta.servlet.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
/*拦截Myfilter程序*/
@WebFilter(filterName = "MyFilter")
public class MyFilter implements Filter {
public void init(FilterConfig config) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.write("Hello MyFilter");
}
public void destroy() {
}
}
标签:AAAjavaweb,复习,void,name,import,servlet,public,String
From: https://www.cnblogs.com/qyj-ks/p/18241848