论坛首页 Java版 Struts

发现struts2一个奇怪的问题

浏览 789 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2008-04-14 关键字: struts2的文件上传
我用struts2做文件上传时,页面加了css之后出错了。
上传文件的页面是upload.jsp:
<%@ page language="java"  pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <title>上传图片</title>    
     <base href="<%=basePath%>">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link href="css/font.css" rel="stylesheet" type="text/css" />
  </head>
  
  <body>
  <s:form action="DoUploadPicture.action" method="post" enctype="multipart/form-data">
  	<s:file      label="请选择图片" name="picture" ></s:file>
  	<s:textarea  label="图片介绍"  name="introduce" key="introduce"></s:textarea>
  	<s:submit/>
  </s:form>  	
  </body>
</html>



struts2的action配置是:
<action name="DoUploadPicture" class="pictureAction" method="doUpload">
   <result name="success" type="redirect">/welcome.jsp</result>
   <result name="input">/mediaresource/picture/UploadPicture.jsp</result>
   <interceptor-ref name="fileUpload">
     <param name="allowedTypes">image/bmp,image/png,image/gif,image/jpeg,image/jpg,image/pjpeg
   </param>
   <param name="maximumSize">102400</param>
   </interceptor-ref>
   <interceptor-ref name="defaultStack"></interceptor-ref>			
</action>	


当页面upload.jsp里含有<link href="css/font.css" rel="stylesheet" type="text/css" />
时,文件上传失败,设置断点后发现,struts2的action类里面没有接受到页面传来的参数。
而页面upload.jsp没有<link href="css/font.css" rel="stylesheet" type="text/css" />
这个css时,就可以上传文件成功。
这个问题觉得很困惑,难道是和struts2自己的标签的css样式 冲突?
   
最后更新时间:2008-04-15
是否在web.xml中加了ActionContextCleanUp这个Filter?
   
0 请登录后投票
最后更新时间:2008-04-16
<base  href="<%=basePath%>" ></base>

你的base标签没有写对,没结尾,当然找不到css了。
   
0 请登录后投票
最后更新时间:2008-04-16
可能是拦截器设置的问题
   
0 请登录后投票
最后更新时间:2008-04-18
tangshuo 写道
是否在web.xml中加了ActionContextCleanUp这个Filter?

确实是这样,加了之后问题就解决了。
谢谢啊!
   
0 请登录后投票
论坛首页 Java版 Struts

跳转论坛:
JavaEye推荐