哎,你加入一java脚本就成了,如:
<%
if(style==1){
%><template:insert template="/test/template1.jsp">
<%
}else{
%>
<template:insert template="/test/template2.jsp"><%
}
%>应该就可以了,你也可以这样写:
<%
if(style==1){
%><template:insert template="/test/template1.jsp">
  <template:put name="header" content="header.html"/>
  <template:put name="content" content="employeeList.jsp?id=${param.id}"/>
  <template:put name="footer" content="footer.html"/>
  <template:put name="test" direct="true" content="test print str"/>
</template:insert><%
}else{
%>
<template:insert template="/test/template2.jsp">
  <template:put name="header" content="header.html"/>
  <template:put name="content" content="employeeList.jsp?id=${param.id}"/>
  <template:put name="footer" content="footer.html"/>
  <template:put name="test" direct="true" content="test print str"/>
</template:insert>
<%
}
%>有时Struts没有办法解决所有问题(当然这里也可以用它的logic标签,意思是一样的),就得加入部分java脚本!

解决方案 »

  1.   

    谢谢明正的回复,我也想过这样做,但我的模版不是一直不变化的
    我的思路是美工可以任意在模版目录下添加模版.系统自动读取模版文件列表供选择,选择了哪个模版,由此信息内容采用这个模版如果采用if(...)(<template:insert template="/test/template2.jsp">)的方法,美工每新做一个模版,我都要重新改一下jsp文件不知道有没有法子改变template=这里的值呢?
      

  2.   

    我也没这样做过,可否试试类似于这样的形式:<template:insert template="/test/template<%= yourstylebeanname.style%>.jsp">
      

  3.   

    <template:insert template="/test/template<%=style%>.jsp">
      

  4.   

    感谢各位的回复url是这样的
    test.jsp?id=*  只传递了一个信息ID值,
    所的我在<template:put name="content" content="employeeList.jsp?id=${param.id}"/>
    用el语句得到ID.将ID传入employeeList.jsp开始我想这样,test.jsp?id=*&style=*
    然后test.jsp中<template:insert template="/test/template${param.style}.jsp">
    但这样浏览者可以改变样式的值
    因为test.jsp并没有操作数据库.style的值是从action中传入的
    但struts不能嵌套标签
    比如<template:insert template="/test/template<bean:write name="style" scope="request">.jsp">是会出错的现在的问题不知道怎么样action的style的值怎么传到<template:insert template="/test/template这里来.jsp">
      

  5.   

    象fmzbj 说的那样做呢
    闲那种方式实现的不好 ?
      

  6.   

    会出现这样的错误/templates/test/test.jsp:5: interpolated runtime values are forbidden by
    the JSP spec at `/templates/test/template<%=style%>.jsp'
      

  7.   

    fmzbj的方法是可以的.但不能在不修改test.jsp文件的情况,添加模版
      

  8.   

    那就别用Struts的标签了,换一种别的组合视图方式,现在那么多种,freeer等,不过我没有实际用过,不能给你提供第一手资料,Struts的这些东西我倒熟,可用起来得却不是很得心应手。
      

  9.   

    to cnidb(老菜) 
    我的短消息不知道为什么不能回复关于过滤器的问题  应该可以过滤目录的啊  有没有具体的api我不清楚 不过自己写算法 去比较字串 来判断url里面有没有特定目录应该行的通