Struts2.0中Tiles框架使用(我想使index页面根据用户选中某一模板文件来动态的生成index页面?请问该怎么解决) 难道没有人用过tiles框架么?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 最近闲着无事,琢磨了一下struts2.06的tiles使用。以下是一些简单使用的步骤。1.在WEB-INF/lib下加入所需的jar包 commons-digester-1.6.jar, xwork-2.0.1.jar, tiles-core-2.0-20070207.130156-4.jar, tiles-api-2.0-20070207.130156-4.jar, struts2-tiles-plugin-2.0.6.jar, struts2-core-2.0.6.jar2.修改web.xml 为以下内容 <?xml version="1.0" encoding="UTF-8"?><web-app 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.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.apache.tiles.listener.TilesListener</listener-class> </listener></web-app>3.在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://struts.apache.org/dtds/tiles-config_2_0.dtd"><tiles-definitions> <definition name="showcase.index" template="/tiles/layout.jsp"> <put name="title" value="Tiles Showcase"/> <put name="header" value="/tiles/header.jsp"/> <put name="body" value="/tiles/body.jsp"/> </definition></tiles-definitions>4.struts.xml 为:<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.devMode" value="true" /> <constant name="struts.ui.theme" value="simple" /> <include file="struts-conf/struts-test.xml" /> </struts>5.struts-test.xml文件为:<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="test" namespace="/test" extends="tiles-default"> <!-- <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/> </result-types> --> <global-results> <result name="login"><param name="location">/user/login.jsp</param></result> </global-results> <action name="sample" class="com.lhx.test.action.TilesAction" method="inputIndex" > <result name="success" type="tiles">showcase.index</result> </action> </package></struts>6.注意要在每个jsp文件中加入<%@ page contentType="text/html; charset=UTF-8"%> struts2 上传问题 在线等答案!错在上的很么地方了! jsf显示图片列表问题 struts,问个简单的 jdk配置问题 上传图片到Oracle的BLOB字段中的问题 求个大神来看下 (简单30分!)Jsp+access中文乱码问题! 在jboss中ejbql出错,求教 sessionFactory注入问题? SHH 整合出现的错误,相信大家都见过,帮我解决行吗? JSP中怎样把变量值输出到text文本框啊?帮帮忙
1.在WEB-INF/lib下加入所需的jar包
commons-digester-1.6.jar,
xwork-2.0.1.jar,
tiles-core-2.0-20070207.130156-4.jar,
tiles-api-2.0-20070207.130156-4.jar,
struts2-tiles-plugin-2.0.6.jar,
struts2-core-2.0.6.jar
2.修改web.xml 为以下内容
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.tiles.listener.TilesListener</listener-class>
</listener>
</web-app>3.在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://struts.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="showcase.index" template="/tiles/layout.jsp">
<put name="title" value="Tiles Showcase"/>
<put name="header" value="/tiles/header.jsp"/>
<put name="body" value="/tiles/body.jsp"/>
</definition>
</tiles-definitions>
4.struts.xml 为:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<include file="struts-conf/struts-test.xml" />
</struts>
5.struts-test.xml文件为:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="test" namespace="/test" extends="tiles-default">
<!-- <result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types> -->
<global-results>
<result name="login"><param name="location">/user/login.jsp</param></result>
</global-results>
<action name="sample" class="com.lhx.test.action.TilesAction" method="inputIndex" >
<result name="success" type="tiles">showcase.index</result>
</action>
</package>
</struts>
6.注意要在每个jsp文件中加入<%@ page contentType="text/html; charset=UTF-8"%>