eclipse学习(第二章:初识ssh)——23.struts整合Tiles
前言
本文是参考自https://www.w3cschool.cn/struts_2/struts_tiles.html做的一个实践日志记录。
jar包下载地址
相关jar包请到该网站下载,下载一个all版本吧
https://struts.apache.org/download.cgi
初始化项目以及jar包拉取
这里需要的将上面网站下载下来的解压后找到lib文件夹,将跟tile有关的jar包拉进去,然后有个联系包struts2-tiles-plugin-2.3.37,然后导入一些struts的包即可。
创建MenuAction
MenuAction ,这里主要是创建两个方法作为action调用
package com.czx.tiles.action;
import com.opensymphony.xwork2.ActionSupport;
public class MenuAction extends ActionSupport {
public String tiger() {
return "tiger";
}
public String lion() {
return "lion";
}
public String baseLayout() {
return "baseLayout";
}
}
找图片
百度找三张,分别是老虎,狮子,转换的图片,然后存放到新建的images文件夹下
修改web.xml
这里主要是做一个配置文件位置指定以及监听器的处理
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ssh_learn_tiles_integration</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.st