JavaBean
实体类
JavaBean有特定写法:
- 必须有无参构造
- 属性必须私有
- 必须有对应的get/set方法
一般用来和数据库的字段做映射 ORM
ORM:对象关系映射
MVC三层架构
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6gjXKgKZ-1625406277608)(C:\Users\henry\AppData\Roaming\Typora\typora-user-images\image-20210704162658210.png)]
Model
- 业务处理:业务逻辑(Service)
- 数据持久层:CRUD(Dao)
View
- 展示数据
- 提供链接发起Servlet请求(a,form,img…)
Controller (Servlet)
Filter(重点)
shiro:使用filter实现
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-giATLnDB-1625406277609)(C:\Users\henry\AppData\Roaming\Typora\typora-user-images\image-20210704163647024.png)]
public class ShowFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("init...........");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=UTF-8");
System.out.println("执行前");
chain.doFilter(request,response);
System.out.println("执行后");
}
@Override
public void destroy() {
System.out.println("destory..............");
}
}
<servlet-mapping>
<servlet-name>showHello</servlet-name>
<url-pattern>/show</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>showHello</servlet-name>
<servlet-class>com.learn.cs.ShowHello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>showHello2</servlet-name>
<url-pattern>/cs/show</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>showHello2</servlet-name>
<servlet-class>com.learn.cs.ShowHello</servlet-class>
</servlet>
<filter>
<filter-name>showFilter</filter-name>
<filter-class>com.learn.filter.ShowFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>showFilter</filter-name>
<url-pattern>/cs/show</url-pattern>
</filter-mapping>
监听器
public class MyListener implements HttpSessionListener {
@Override
public void sessionCreated(HttpSessionEvent se) {
System.out.println("创建会话:"+se.getSession().getId());
ServletContext sc = se.getSession().getServletContext();
Integer personCount = (Integer) sc.getAttribute("count");
if(personCount==null)
{
personCount =1;
}
else
{
personCount = personCount+1;
}
sc.setAttribute("count",personCount);
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
System.out.println("销毁会话:"+se.getSession().getId());
}
}
<listener>
<listener-class>com.learn.listener.MyListener</listener-class>
</listener>
过滤器\监听器常见应用
监听器:GUI编程
过滤器拦截登录,访问页面请求
-class>com.learn.listener.MyListener
# 过滤器\监听器常见应用
监听器:GUI编程
过滤器拦截登录,访问页面请求
|