Struts是基于MVC设计模式的Web应用框架
目的:减少运用mvc设计模型来开发web应用的时间
MVC是模型视图控制器(Model View Controller)一种软件设计典范,用一种业务逻辑,界面显示分离的方法组织代码,用一种业务逻辑、数据、界面显示分离的方法组织代码,将业务逻辑聚集到一个部件里,在改进和个性化定制界面及用户交互的同时,不需要重新编写业务逻辑
IDEA-入门案例
1. 导入包
https://download.csdn.net/download/qq_37143903/12502099
2. 创建一个Action类
public class HelloWordAction extends ActionSupport {
@Override
public String execute() throws Exception {
System.out.println("execute");
return SUCCESS;
3. 配置文件
、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="defaule" namespace="/" extends="struts-default">
<action name="helloword" class="action.HelloWordAction">
<result>/result.jsp</result>
</action>
</package>
</struts>
web.xml
<?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">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
result.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>This is result</h1>
</body>
</html>
4.测试