1:<img src="<s:property value='%{student.getSpath()}' />" width='240' height="240" />
其中:<s:property value='%{student.getSpath()}' />可能为空,我想让他为空的时候自动换成imageLoad/default.jpg这个路径。
2:接着第一问:当img显示时,如果我把这个图片给换成同名的不同图片,为什么都要在我手动刷新一下才能正常显示新的图片?
3:我用<result name="studentDeleteSuccess">/Student_listAll.action</result>转到同一个Action为什么会报错啊,过我改成<result name="studentDeleteSuccess">/deleteStudent_success.html</result>,也就是先转到html页面,再在html中转到Student_listAll.action又可以呢?
我的web.xml配置:
  </welcome-file-list>
    <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>/*</url-pattern>
  </filter-mapping>
struts.xml:
<action name="Student_*" class="org.wjl.mgqs.action.StudentAction" method="{1}">
         <result name="listAll">/listStudent.jsp</result>
<result name="studentDeleteSuccess">/Student_listAll.action</result>
</action>

解决方案 »

  1.   

    问题1:
    一般应该在Servlet中把这种逻辑关系处理掉,如果非要在JSP中,就用: <c:if test="">分别写两种情况。问题2:
    你名字既然一样,浏览器智能的认为直接从缓存中获取就行了啊,为啥还要去服务器端取?除非你的图片的HEAD信息中包含了no-cache等信息,要求服务器严禁缓存。验证码类的就经常会这样做问题3:
    转到另一个Action,需要用 type="redirect-action" 或者chain。
      

  2.   

    no-cache我都加了的,起不到效果,对了我的jsp界面是嵌套在一个Iframe中的?有影响吗?
    如果用<s:if>怎么写啊,我的src中的值是用<s:property>来得到的,这个能嵌套吗?能不能像<s:iterator var="" value="">一样起个别名用啊?
      

  3.   

    一个YD的做法,是给文件名后面增加毫无意义的随机数当参数,比如: xxoo.jpg?param=12323525或者用choose吧(if也差不多,写两次而已):
    <c:choose> 
    <c:when test="%{student.getSpath() != null}"> 
      <img src="<s:property value='%{student.getSpath()}' />" width='240' height="240" /> 
    </c:when> 
    <c:otherwise> 
      <img src="<s:property value='imageLoad/default.jpg' />" width='240' height="240" />
    </c:otherwise> 
    </c:choose> 
      

  4.   

    显示默认图片算是解决了(如下):
    <s:set name="studentImagePath" value="%{student.getSpath()}" />
    <s:if test="#studentImagePath != null">
    <img src="<s:property value='#studentImagePath' />" width='240' height="240" />
    </s:if>
    <s:else>   
         <img src='imageLoad/default.jpg' width='240' height="240" />
         </s:else> 
    但是当图片更新名字不改变的时候图片还是不能自动更新,都要手动刷新一下,因为我是用的学生的学号作为图片的存储名称的,不太适合用随机数的方法吧!
    像if (request.getProtocol().compareTo("HTTP/1.0")==0)
    response.setHeader("Pragma","no-cache");
    if (request.getProtocol().compareTo("HTTP/1.1")==0)
    response.setHeader("Cache-Control","no-cache");
    response.setDateHeader("Expires",0);这些我都加了的,但是没有效果。
    在这里想在确认一下:
    struts2的action在每次接受新的数据之前都会把原来的数据清空吗?我观察了下 好像是这样的。
      

  5.   


    如果不是这样,并发情况下不就乱套了?检查下IE关于缓存的配置项,是否选择了“从不检查”?
    实在不行就只能用我3楼说的:给文件名后面增加毫无意义的随机数当参数,比如: stuno.jpg?param=12323525