IE7+ 获取input file 全路径

    技术2022-05-20  37

    IE6+以后使用input file标签用来选择文件的话,传送到服务器端不能获取文件的全路径,只有文件的名称。解决办法如下:

     

    测试环境IE7,FF下面不行,只能获取文件名。

    代码如下:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% 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> <base href="<%=basePath%>"> <title>My JSP 'jquery15.jsp' starting page</title> <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"> <mce:script type="text/javascript" src="js/jquery-1.5.js" mce_src="js/jquery-1.5.js"></mce:script> </head> <body> <form action=""> <input id="name" type="file"> </form> </body> </html> <mce:script type="text/javascript"><!-- $('#name').change(function(){ var path=$(this).val(); alert(path); }) // --></mce:script>

     

     

    在IE7+下面想获取全路径,必须更改IE的安全设置,运行将文件全路径发送的服务器这项打钩。


    最新回复(0)