你可以使用一个js方法来检验你输入的文件名。
如果不是图形文件的结尾不允许提交就行了吧。
fileName = document.all.theFile.value;
然后使用字符串的方法得到文件名的后缀,判断是否是你要接收的文件
类型这样就可以了吧。

解决方案 »

  1.   

    但当我用<html:file property="theFile" accept="image/gif"/>时怎么调用js!
      

  2.   

    有谁用过<html:file  property="theFile"  accept="image/gif"/>其中accept=""属性的指点一下!
      

  3.   

    难道accept不是文件类型过滤功能对于的属性吗?
      

  4.   

    没办法!先在Action里作判断吧!
      

  5.   

    我在http://struts.apache.org/userGuide/struts-html.html#file上看了一下,得到这样一个解释:
    Comma-delimited set of content types that the server you submit to knows how to process. This list can be used by the client browser to limit the set of file options that is made available for selection. If not specified, no content type list will be sent.
    是不是说,应该用逗号作为分隔符?我这里没有环境,你试一下?
      

  6.   

    建議在Action裡做好,Action本來就有這麽強的功能,爲什麽不用呢~~
      

  7.   

    <html:file property="string" accept="image/jpeg, image/gif"/>