我在index.jsp这个页面中使用了 <tiles:insert definition="student_definition"/>
在这个tiles中的main页面中使用了<logic:forward/>标签。可以就是不转发。而单独执行这个页面就会转发。大家帮瞧瞧什么问题啊。。
代码如下 : 红色的部分就是要执行的代码块~
1. index.jsp:<%@ page language="java" pageEncoding="gbk"%><%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %><tiles:insert definition="student_definition"/>
2.struts-config.xml : <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<data-sources />
<form-beans >
<form-bean name="studentForm" type="com.mlong.zjj.form.StudentForm" />
<form-bean name="lookUpDispatchForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="login" type="java.lang.String"/>
<form-property name="login1" type="java.lang.String"/>
</form-bean>
<form-bean name="queryByLikeForm" type="com.yourcompany.struts.form.QueryByLikeForm" />
</form-beans>
<global-exceptions />
<global-forwards >
<forward name="failture" path="/failtue.jsp"/>
<forward name="queryAllStudents" path="/studentOper.do?method=queryAll"/> <forward name="getClasses" path="/findClass.do?method=queryAll"/>
</global-forwards>
<action-mappings >
<action
attribute="studentForm"
input="/admin/add_student.jsp"
name="studentForm"
parameter="method"
path="/student"
scope="session"
type="com.mlong.zjj.action.StudentAction" >
<forward name="suc_update" path="/admin/update_student.jsp"/>
</action>
<action
path="/myLookUpDispatchAction"
type="com.yourcompany.struts.action.MyLookUpDispatchActionAction"
name="lookUpDispatchForm"
validate="false"
scope="request"
input="/LookUpDispatcchAction.jsp"
parameter="action"
/>
<action
attribute="queryByLikeForm"
input="/index.jsp"
name="queryByLikeForm"
path="/queryByLike"
scope="request"
type="com.mlong.zjj.action.QueryByLikeAction" />
<action
parameter="method"
path="/studentOper"
type="com.mlong.zjj.action.StudentOperAction"
validate="false" >
<forward name="index" path="/index.jsp"></forward>
<forward name="update_student" path="/admin/update_student.jsp" redirect="false"/>
</action>
<action path="/findClass"
type="com.yourcompany.struts.action.FindClassAction"
parameter="method" />
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/mydefine/mydefine.xml"/>
<set-property property="definitions-parser-validate" value="true"/>
</plug-in>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/add_student_validator.xml"/>
<set-property property="stopOnFirstError" value="true"/>
</plug-in>
</struts-config>3.mydefine.xml <?xml version="1.0"?><!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
"http://struts.apache.org/dtds/tiles-config_1_1.dtd"><tiles-definitions> <definition name="student_definition" page="/WEB-INF/commons/template.jsp">
<put name="header" value="/WEB-INF/commons/head.jsp"/>
<put name="lefter" value="/WEB-INF/commons/left.jsp"/>
<put name="main" value="/WEB-INF/commons/main.jsp"/>
<put name="footer" value="/WEB-INF/commons/foot.jsp"/>
</definition>
</tiles-definitions>
4. commons/head.left.main.foot.template.页面: 4.1 head.jsp: <table width="1003" height="100">
<tr><td align="center"> <h1>0000000</h1></td></tr>
</table>
4.2 left.jsp
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <table width="200">
<tr><td>11</td></tr>
<tr><td><html:link page="/admin/add_student.jsp">add</html:link></td></tr>
<tr><td>222</td></tr> </table>4.3 foot.jsp
<table width="1003" height="100">
<tr><td align="center"> <h1>0000000</h1></td></tr>
</table>
在这个tiles中的main页面中使用了<logic:forward/>标签。可以就是不转发。而单独执行这个页面就会转发。大家帮瞧瞧什么问题啊。。
代码如下 : 红色的部分就是要执行的代码块~
1. index.jsp:<%@ page language="java" pageEncoding="gbk"%><%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %><tiles:insert definition="student_definition"/>
2.struts-config.xml : <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<data-sources />
<form-beans >
<form-bean name="studentForm" type="com.mlong.zjj.form.StudentForm" />
<form-bean name="lookUpDispatchForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="login" type="java.lang.String"/>
<form-property name="login1" type="java.lang.String"/>
</form-bean>
<form-bean name="queryByLikeForm" type="com.yourcompany.struts.form.QueryByLikeForm" />
</form-beans>
<global-exceptions />
<global-forwards >
<forward name="failture" path="/failtue.jsp"/>
<forward name="queryAllStudents" path="/studentOper.do?method=queryAll"/> <forward name="getClasses" path="/findClass.do?method=queryAll"/>
</global-forwards>
<action-mappings >
<action
attribute="studentForm"
input="/admin/add_student.jsp"
name="studentForm"
parameter="method"
path="/student"
scope="session"
type="com.mlong.zjj.action.StudentAction" >
<forward name="suc_update" path="/admin/update_student.jsp"/>
</action>
<action
path="/myLookUpDispatchAction"
type="com.yourcompany.struts.action.MyLookUpDispatchActionAction"
name="lookUpDispatchForm"
validate="false"
scope="request"
input="/LookUpDispatcchAction.jsp"
parameter="action"
/>
<action
attribute="queryByLikeForm"
input="/index.jsp"
name="queryByLikeForm"
path="/queryByLike"
scope="request"
type="com.mlong.zjj.action.QueryByLikeAction" />
<action
parameter="method"
path="/studentOper"
type="com.mlong.zjj.action.StudentOperAction"
validate="false" >
<forward name="index" path="/index.jsp"></forward>
<forward name="update_student" path="/admin/update_student.jsp" redirect="false"/>
</action>
<action path="/findClass"
type="com.yourcompany.struts.action.FindClassAction"
parameter="method" />
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/mydefine/mydefine.xml"/>
<set-property property="definitions-parser-validate" value="true"/>
</plug-in>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/add_student_validator.xml"/>
<set-property property="stopOnFirstError" value="true"/>
</plug-in>
</struts-config>3.mydefine.xml <?xml version="1.0"?><!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
"http://struts.apache.org/dtds/tiles-config_1_1.dtd"><tiles-definitions> <definition name="student_definition" page="/WEB-INF/commons/template.jsp">
<put name="header" value="/WEB-INF/commons/head.jsp"/>
<put name="lefter" value="/WEB-INF/commons/left.jsp"/>
<put name="main" value="/WEB-INF/commons/main.jsp"/>
<put name="footer" value="/WEB-INF/commons/foot.jsp"/>
</definition>
</tiles-definitions>
4. commons/head.left.main.foot.template.页面: 4.1 head.jsp: <table width="1003" height="100">
<tr><td align="center"> <h1>0000000</h1></td></tr>
</table>
4.2 left.jsp
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <table width="200">
<tr><td>11</td></tr>
<tr><td><html:link page="/admin/add_student.jsp">add</html:link></td></tr>
<tr><td>222</td></tr> </table>4.3 foot.jsp
<table width="1003" height="100">
<tr><td align="center"> <h1>0000000</h1></td></tr>
</table>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ page language="java" pageEncoding="gbk"
import="java.util.*,com.mlong.zjj.bean.*"%><logic:notPresent name="students">
<%
System.out.println("no students 1111551111");
%>
<logic:forward name="queryAllStudents" />
</logic:notPresent><logic:present name="students">
<bean:size name="students" id="s_size" />
<logic:lessEqual value="0" name="s_size">
<font color="red">没有相关学生信息.</font>
</logic:lessEqual>
<logic:greaterEqual value="1" name="s_size"> <table width="803">
<tr>
<th align="center">
<bean:message key="student.card" />
</th>
<th align="center">
<bean:message key="student.name" />
</th>
<th align="center">
<bean:message key="student.sex" />
</th>
<th align="center">
<bean:message key="student.age" />
</th>
<th align="center">
<bean:message key="student.oper" />
</th>
</tr> <logic:iterate id="student" name="students"
type="com.mlong.zjj.bean.Student">
<tr>
<td align="center">
<bean:write name="student" property="card" />
</td>
<td align="center">
<bean:write name="student" property="name" />
</td>
<td align="center">
<bean:define id="sex" name="student" property="sex" /> <logic:equal value="0" name="sex">
<bean:message key="add_student.female" />
</logic:equal> <logic:equal value="1" name="sex">
<bean:message key="add_student.male" />
</logic:equal>
</td>
<td align="center">
<bean:write name="student" property="age" />
</td>
<td align="center"> <%
HashMap hm1 = new HashMap();
hm1.put("method", "update");
hm1.put("s_id", ((Student) pageContext
.getAttribute("student")).getId());
pageContext.setAttribute("update", hm1);
%>
<html:link page="/studentOper.do" name="update">
<bean:message key="student.oper.update" />
</html:link>
<%
HashMap hm = new HashMap();
hm.put("method", "del");
hm.put("s_id", ((Student) pageContext
.getAttribute("student")).getId());
pageContext.setAttribute("del", hm);
%>
<html:link page="/studentOper.do" name="del">
<bean:message key="student.oper.del" />
</html:link>
</td>
</tr> </logic:iterate> <bean:size id="length" name="students" />
<tr>
<td align="right" colspan="4">
搜索结果共 [
<font color="red"><bean:write name="length" />
</font>]项
</td>
<td></td>
</tr>
</table>
</logic:greaterEqual></logic:present><table width="803"> <tr>
<td>
<%
ArrayList list = new ArrayList();
list.add(new org.apache.struts.util.LabelValueBean("学号", "card"));
list.add(new org.apache.struts.util.LabelValueBean("姓名", "name"));
pageContext.setAttribute("queryoption", list);
%>
<html:form action="/queryByLike.do">
<html:select property="queryby">
<html:options collection="queryoption" property="value"
labelProperty="label" />
</html:select>
<html:text property="keyword" />
<font color="red"><html:errors property="null.keyword" />
</font>
<html:submit />
</html:form> </td>
</tr>
</table>5. StudentOperAction/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.mlong.zjj.action;import java.util.ArrayList;
import java.util.List;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;import com.mlong.zjj.bean.Student;
import com.mlong.zjj.impl.DAOImpl.StudentImpl;/**
* MyEclipse Struts
* Creation date: 11-11-2007
*
* XDoclet definition:
* @struts.action parameter="method"
*/
public class StudentOperAction extends DispatchAction {
/*
* Generated Methods
*/ /**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward queryAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("queryall method execute ...."); List al=new ArrayList();
StudentImpl s_impl=new StudentImpl();
al =s_impl.queryAll();
request.setAttribute("students", al);
return mapping.findForward("index");
}
}
以上执行index.jsp时。只打印出了。
System.out.println("no students 1111551111");而StudentOperAction 中的
System.out.println("queryall method execute ....");没有执行。如果我把main.jsp页面拿一份出来。单执行这个页面就 可以了。(重启TOMCAT)
一切正 常 。是不是在<tiles>中不能用<forward>啊。
还是怎么回事尼。大家帮帮忙啊。。
谢谢了。