java - 文件对话框中可接受的扩展名

标签 java file jsp spring-mvc

如何使用 JSPSpring MVC 在文件对话框中设置可接受的扩展名?我就是这样做的:

<form:form method="post" enctype="multipart/form-data"
        modelAttribute="uploadedFile" action="fileUpload">
        <table>
            <tr>
                <td>Upload File:</td>
                <td><input type="file" name="file" /></td>
                <td style="color: red; font-style: italic;"><form:errors
                        path="file" /></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Upload" /></td>
                <td></td>
            </tr>
        </table>
    </form:form>

我可以用 Spring 做这样的事情吗:

<input type="file" name="file" ext="xml, txt"/>

最佳答案

试试这个..

<html>
<body>
<input type="file" name="fi" accept="text/xml, text/plain"/>
</body>
</html>

你不需要 spring 来做到这一点。这只是简单的 HTML。

关于java - 文件对话框中可接受的扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21601993/

相关文章:

java - 安卓 : Constraint Layout Set Constraint top programmatically?

java - Spring @Autowired变量在@Component内部为空

Java、Mac 操作系统、Windows 和 Linux

c - 使用 fscanf() 读取一行时遇到问题

java - InputStream 当部分名称已知时? (安卓)

java - 使用 HTML 表单文本输入框在 SQL 数据库中添加/编辑数据

java - 无法将客户端的时间戳发送到服务器

java - 关于java中线程的一些问题

c# - 我需要解析 250 个文件,总计 1gb 的数据并将其上传到 SQL 服务器。我能比这更有效率吗?

java - 在 Spring MVC 中 - model.addAttribute 动态数据的用法以及如何将数据放置在 jsp 文件中