搭建Struts2 与 Tiles 框架整合示例

本文介绍如何在MyEclipse环境下搭建Struts2与Tiles框架整合的示例项目,包括配置web.xml、struts.xml等关键文件,实现自定义布局及组件复用。

搭建Struts2 与 Tiles 框架整合示例

 

 

环境:MyEclipse 8.5 + TOMCAT6 +JDK1.6
一、新建web工程。例如:s2tile2。
二、使用向导添加Struts2.1功能:
引入Struts 2 Core Libraries和Struts 2 Tiles Libraries两个类库包。

三、新建s2tile2\WebRoot\index.jsp文件,内容如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <body>
    <a href="go.action">test</a>
  </body>
</html>


四、修改s2tile2\WebRoot\WEB-INF\web.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>

 

 <listener>
  <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
 </listener>
 <context-param>
  <param-name>org.apache.tiles.CONTAINER_FACTORY</param-name>
  <param-value>
      org.apache.struts2.tiles.StrutsTilesContainerFactory
    </param-value>
 </context-param>

 <context-param>
  <param-name>
   org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
  <param-value>/WEB-INF/tiles.xml</param-value>
 </context-param>

 
 <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>*.action</url-pattern>
 </filter-mapping>
</web-app>

五、修改s2tile2\src\struts.xml,内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
 <package name="default" extends="tiles-default">
  <action name="go" class="com.action.MyAction">
   <!--result name="success">/next.jsp</result-->
   <result name="success" type="tiles">myapp.homepage</result>
  </action>
 </package>
</struts>   

六、建立s2tile2\src\com\action\MyAction.java类,内容如下:
package com.action;
import com.opensymphony.xwork2.ActionSupport;
public class MyAction extends ActionSupport{
 public String execute() throws Exception {
  super.execute();
  System.out.println("MyAction execute something ...");
  return SUCCESS;
 }
}

七、新建s2tile2\WebRoot\WEB-INF\tiles.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
 <definition name="myapp.homepage" template="layout.jsp">
  <put-attribute name="title" value="Tiles tutorial homepage" />
  <put-attribute name="header" value="/tiles/header.jsp" />
  <put-attribute name="menu" value="/tiles/menu.jsp" />
  <put-attribute name="body" value="/tiles/cBody.jsp" />
  <put-attribute name="footer" value="/tiles/footer.jsp" />
 </definition>
</tiles-definitions>

八、从Struts 2 Tiles Libraries中的tiles-jsp-2.0.6.jar包中的META-INF\tld中的tiles-jsp.tld文件释放到s2tile2\WebRoot\WEB-INF\tiles-jsp.tld目录下。

九、新建s2tile2\WebRoot\layout.jsp文件,内容如下:
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/tiles-jsp.tld" prefix="tiles"%>
<html>
    <head>
       <title></title>
    </head>
    <body>
       <table width="768px" height="800px" border="2" align="center">
           <tr>
              <td colspan="2" align="center" valign="top" width="768px" height="100px" bgcolor="#80ff80">
                  <tiles:insertAttribute name="header" />
              </td>
           </tr>
           <tr>
              <td align="center" width="150px" height="800px" bgcolor="#00ff00">
                  <tiles:insertAttribute name="menu" />
              </td>
              <td align="right" width="618px" height="800px" bgcolor="#ff80c0">
                  <tiles:insertAttribute name="body" />
              </td>
           </tr>
           <tr>
              <td colspan="2" bgcolor="#00ff40" height="100px">
                  <tiles:insertAttribute name="footer" />
              </td>
           </tr>
       </table>
    </body>
</html>

 

标签说明:

1、<tiles:insertAttribute name="body" />:返回"body"对应的页面的内容信息。

2、<tiles:getAsString name="body" />:返回"body"对应的值,即路径信息。

 

十、依次新建下列文件:
s2tile2\WebRoot\tiles\cBody.jsp、
s2tile2\WebRoot\tiles\footer.jsp、
s2tile2\WebRoot\tiles\header.jsp、
s2tile2\WebRoot\tiles\menu.jsp,
以上文件内容任意,仅用于测试。

十一、发布测试:OK。

 

MATLAB代码实现了一个基于多种智能优化算法优化RBF神经网络的回归预测模型,其核心是通过智能优化算法自动寻找最优的RBF扩展参数(spread),以提升预测精度。 1.主要功能 多算法优化RBF网络:使用多种智能优化算法优化RBF神经网络的核心参数spread。 回归预测:对输入特征进行回归预测,适用于连续值输出问题。 性能对比:对比不同优化算法在训练集和测试集上的预测性能,绘制适应度曲线、预测对比图、误差指标柱状图等。 2.算法步骤 数据准备:导入数据,随机打乱,划分训练集和测试集(默认7:3)。 数据归一化:使用mapminmax将输入和输出归一化到[0,1]区间。 标准RBF建模:使用固定spread=100建立基准RBF模型。 智能优化循环: 调用优化算法(从指定文件夹中读取算法文件)优化spread参数。 使用优化后的spread重新训练RBF网络。 评估预测结果,保存性能指标。 结果可视化: 绘制适应度曲线、训练集/测试集预测对比图。 绘制误差指标(MAE、RMSE、MAPE、MBE)柱状图。 十种智能优化算法分别是: GWO:灰狼算法 HBA:蜜獾算法 IAO:改进天鹰优化算法,改进①:Tent混沌映射种群初始化,改进②:自适应权重 MFO:飞蛾扑火算法 MPA:海洋捕食者算法 NGO:北方苍鹰算法 OOA:鱼鹰优化算法 RTH:红尾鹰算法 WOA:鲸鱼算法 ZOA:斑马算法
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值