一、Struts2的概念

使用优势:1)自动封装参数

     2)参数校验

     3)结果的处理(转发|重定向)

     4)国际化

     5)显示等待页面

     6)防止表单重复提交

Struts2具有更加先进的架构以及思想

Struts2的历史:1>Struts1与Struts1的区别技术上没有关系

        2>struts2的前身是webwork框架

二、搭建Struts2框架

首先下载Struts2的开发包,官网:https://struts.apache.org/

1、创建一个web工程并导入jar包

2、创建一个jsp页面

在WebContent下创建hello.jsp:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>hello world!</h1>
</body>
</html>

3、书写Action类

 package cn.itheima.a_hello;

 public class HelloAction {

     public String hello(){
System.out.print("hello world!");
return "success";
}
}

4、书写src下的struts.xml

Action类写好之后,Struts2框架如何识别它就是一个Action呢,需要对Action类进行配置

先导入约束(window--->Preferences--->XML--->XML Catalog--->User Specified Entries窗口,点击Add按钮)

在src下书写配置文件struts.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="hello" namespace="/hello" extends="struts-default">
<action name="HelloAction" class="cn.itheima.a_hello.HelloAction" method="hello">
<result name="success">/hello.jsp</result>
</action>
</package>
</struts>

5、将struts2核心过滤器配置到web.xml

web层的框架特点就是基于前端控制器的模式,这个前端控制器由过滤器实现,所以需要配置Struts2的核心过滤器,这个过滤器的名称是StrutsPrepareAndExecuteFilter。

在web.xml中进行如下配置:

6、发布到服务器并测试

最新文章

  1. You are note Hk
  2. javascript继承(四)—prototype属性介绍
  3. 【BZOJ】1221: [HNOI2001] 软件开发(最小费用最大流)
  4. 十问 Linux 虚拟内存管理 (glibc) (二)
  5. 编译 proto 文件到指定语言的代码
  6. 第四篇:Eclipse Android app 工程迁移到 Android Studio
  7. 启用oracle 11g自己主动收集统计信息
  8. ASP.NET Core 2.0 : 六. 举个例子来聊聊它的依赖注入
  9. Powerdesigner16 逆向 postgresql9.2
  10. mysql查看正在执行的sql语句
  11. 渲染函数render和函数式组件
  12. 使用Charles抓取APP之HTTPS请求
  13. Jstl标签汇总
  14. Libre 6004 「网络流 24 题」圆桌聚餐(网络流,最大流)
  15. python测试开发django-20.添加创建时间DateTimeField
  16. jQuery解决IE6、7、8不能使用 JSON.stringify 函数的问题
  17. Struts2 学习笔记--Action Method--接收参数
  18. JavaScript中的陷阱(关于变量声明,函数)
  19. bzoj4569-萌萌哒
  20. Web开发入门知识小总结

热门文章

  1. Jquery常见操作多选框/复选框/checkbox
  2. 【转载】push to origin/master was rejected错误解决方案
  3. Python语言数据结构和语言结构(2)
  4. C++string和int的相互转化
  5. java IO框架分析
  6. linux下Qt程序编译运行
  7. 【hihocoder 1298】 数论五·欧拉函数
  8. Feign 负载均衡
  9. (31)Spring Boot导入XML配置【从零开始学Spring Boot】
  10. MySQL特异功能之:Impossible WHERE noticed after reading const tables