【问题标题】:<input type="file"> reads only file name not full path<input type="file"> 只读取文件名而不是完整路径
【发布时间】:2011-03-16 15:59:26
【问题描述】:

我正在使用 Glassfish 服务器。我已经看到了 apache 文件上传来解决它...但我想在 glassfish 服务器中实现它。

image.html

<form action="" method="post" enctype="multipart/form-data">
    Select a file:
    <input type="file" name="first" id="first" />
    <br />
    <input type="button" name="button" value="upload" id="button" />
    <p id="test"></p>
   <img src='Unknown.png'  id="profile_img" height="200px" width="150px" />
</form>

test.js

$(document).ready(function() {
    var filepath= $("#first");
    $('#button').click(function() {
        $.ajax({
            type:       "post",
            url:        "imageservlet",
            data:       "user="+filepath.val(),
            success:    function(msg) {
                            $("#profile_img").attr('src',msg);
                            $("#test").html(msg).fadeIn("fast");
                        }
        });
    });
});

imageservlet.java

String user=request.getParameter("user");
out.print(user);

输出是文件名而不是完整路径。

【问题讨论】:

  • 这是特定于浏览器的。相关:How to get full file path in Firefox?
  • 可以给我在jsp中做服务器端编码的例子。但我使用的是glassfish而不是apache服务器。
  • 那个链接不是用来装饰的 :) 点击阅读。它又包含另一个链接。

标签: jquery html glassfish servlets


【解决方案1】:

浏览器对此的处理方式不同。并非所有浏览器都允许您访问完整的路径名(从安全角度来看,这非常有意义)。

【讨论】:

  • 从“此控件旨在上传文件”的角度来看,它也很有意义。它不是描述文件在客户端硬盘上的位置的工具。这些信息在 WWW 的上下文中是无用的。
猜你喜欢
  • 2011-01-13
  • 2011-08-12
  • 2010-11-27
  • 1970-01-01
  • 2011-01-10
  • 2012-03-01
  • 2012-09-13
  • 1970-01-01
  • 2011-10-20
相关资源
最近更新 更多