先下载一个空白的war包(struts2的例子): 链接:https://pan.baidu.com/s/1ZSDoGOy_MVTu3PsEdM1ujg 密码:dndo
将该war解压之后的结构:
只需要引入一下依赖包即可:
初始项目结构图:
HelloAction.java文件:
package com.rl.action;
public class HelloAction {
public String hello(){
return "success";
}
}
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" extends="struts-default">
<action name="hello" class="com.rl.action.HelloAction" method="hello">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- 配置中央分发器
-->
<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>
success.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>success</h1>
</body>
</html>
部署项目并启动服务器(步骤略)
测试成功: