首页 \ 问答 \ jQuery的FormData不与Servlet一起工作[复制](jquery FormData not working with Servlet [duplicate])

jQuery的FormData不与Servlet一起工作[复制](jquery FormData not working with Servlet [duplicate])

这个问题在这里已经有了答案:

我使用jQuery FormData将一个文件发送到tomcat服务器。 该文件正在服务器上成功接收,但没有收到我用该文件发送的任何其他值。 为了处理文件上传,我使用了http://commons.apache.org/proper/commons-fileupload/http://commons.apache.org/io/ 。 它以某种方式获取我的文件。 但是,当我写

request.getParameter("file")

在下面的代码的servlet中,它返回null。 即使它不显示请求对象中的任何参数。 我不明白它是如何获得文件。 任何人都可以帮我解决这个问题吗?

$('#uploadCourseDetail').click(function() {
    var form_data = new FormData();
    if (!($('#courseDetails').prop('files')[0] == undefined)) {
        var file_data = $('#courseDetails').prop('files')[0];
        form_data.append('file', 'examdetail');
        form_data.append('courseDetails', file_data);
    }
    $.ajax({
        url: 'Exam_TimeTable_Scheduler_bySlots_Web_Project/FileUploadServlet',
        type: 'POST',
        contentType: false,
        processData: false,
        cache: false,
        data: form_data,
        success: function(data) {
            alert("File Uploaded Successfully !");
        }
    });
});

我使用萤火虫追踪请求。 它显示这两个字段正在发送到服务器。 以下是相同的快照: 在这里输入图像描述


This question already has an answer here:

I am sending one file to the tomcat server using jQuery FormData. The file is being received successfully on the server but any other value which I send with the file is not being received. For processing the file upload, I am using http://commons.apache.org/proper/commons-fileupload/ and http://commons.apache.org/io/. It is getting my file somehow. But when I write

request.getParameter("file")

in the servlet for the below code, it returns null. Even it doesn't show any parameter in the request object. I don't understand how it gets the file then. Can anyone help me to solve this?

$('#uploadCourseDetail').click(function() {
    var form_data = new FormData();
    if (!($('#courseDetails').prop('files')[0] == undefined)) {
        var file_data = $('#courseDetails').prop('files')[0];
        form_data.append('file', 'examdetail');
        form_data.append('courseDetails', file_data);
    }
    $.ajax({
        url: 'Exam_TimeTable_Scheduler_bySlots_Web_Project/FileUploadServlet',
        type: 'POST',
        contentType: false,
        processData: false,
        cache: false,
        data: form_data,
        success: function(data) {
            alert("File Uploaded Successfully !");
        }
    });
});

I use firebug to track the requests. It shows that both the fields are being sent to the server. Below is the snapshot for the same:enter image description here


原文:https://stackoverflow.com/questions/43258751
更新时间:2023-05-06 15:05

最满意答案

VSTS Wiki现在支持使用#引用工作项 。 您可以键入#并引用现有工作项。 此功能刚刚完成,并且在我输入时仍在部署。

很快,您就可以将维基链接到工作项。 想象一下这个功能,当你在维基页面上推荐史诗的每个特征时,你可以跟踪你的史诗完成百分比。

您可以尝试分享您的反馈。


VSTS Wiki now supports referencing work items using #. You can type # and reference an existing work item. This feature has just been completed and is still being deployed as I type.

Very soon, you will be able to link a wiki to a work item. Imagine this feature allowing you to track what % of your epic is completed when you refer each feature of the epic on your wiki page.

You can try and share your feedback.

相关问答

更多
  • 只需看看将Git存储库发布到wiki的先决条件 : 您必须具有创建存储库的权限才能将代码发布为wiki。 默认情况下,为Project Administrators组的成员设置此权限。 任何有权贡献Git存储库的人都可以添加或编辑Wiki页面。 任何有权访问团队项目的人,包括利益相关者 ,都可以查看Wiki。 关于利益相关者维基访问的描述: 项目中的利益相关者可以阅读维基页面并查看修订, 但是他们无法执行任何编辑操作 。 例如,利益相关者无法创建,编辑,重新排序或还原对页面的更改。 注意: 具有利益相关者访 ...
  • 您可以通过REST API获取开发链接以获取工作项关系: GET https://account.visualstudio.com/DefaultCollection/_apis/wit/workitems/{workitem ID}?$expand=relations&api-version=1.0 然后,您可以通过输出获取ArtifactLinks中的开发链接。 而Microsoft.VSTS.Build.IntegrationBuild字段不能用于获取VSTS的构建链接 ,因为Microsoft.V ...
  • 应该在TFS服务器中为WIT定义进行一些自定义,以便为工作项分配组。 但是对于VSTS,现在没有任何方法可以自定义WIT定义。 这意味着您无法将工作项分配给VSTS中的组。 您只能将工作项分配给有效用户。 There should be some customization made for the WIT Definition in your TFS server what allow the group to be assigned for Work Items. But for VSTS, there ...
  • 版本控制路径长度限制均适用于VSTS和TFS。 在文章命名限制和约定 (除了部分Team Foundation Build(仅限本地TFS) )之外,所有限制均适用于TFS和VSTS。 因为它列出了适用于以下产品和产品的版本: 在VSTS和TFS中集成了两个版本控制系统: Git和TFVC (Team Foundation版本控制) 。 对于Team Foundation版本控制部分,它显示了TFVC VCS的限制(都可用于TFS和VSTS)。 所以,如果您使用TFVC来管理您的源代码,您可以找到文章中列出 ...
  • 实际上, 利益相关者访问级别的人员不能在分支机构上工作。 为需要输入错误,查看待办事项,板卡,图表和仪表板但没有TFS CAL的用户分配利益相关者访问权限。 利益相关者还可以查看版本并管理版本批准。 利益相关者访问是免费的。 来源链接: 关于访问级别 有关利益主体可用功能的详细信息,请参阅利益相关方访问 用户应具有基本访问权限或包含代码功能的VS Enterprise 。 此外,它能够禁止他看到你在VSTS上的任何其他项目。 这是VSTS中称为权限的另一个概念。 不要将他添加到任何其他项目团队组中,期望他将 ...
  • UI查询结果中没有显示链接类型的功能。 您可以通过REST API获取它: 运行存储的查询 There isn’t such feature to display link type in UI Query Result. You can get it through REST API: Run a stored query
  • 对于第一个查询,您可以添加一个自定义字段,其中Allow assigning to groups所选Allow assigning to groups 。 这样,你可以分配给一个组: 有用的链接: https://docs.microsoft.com/en-us/vsts/work/customize/process/customize-process-field?view=vsts For your first query, you could add a custom field with Allow ...
  • VSTS Wiki现在支持使用#引用工作项 。 您可以键入#并引用现有工作项。 此功能刚刚完成,并且在我输入时仍在部署。 很快,您就可以将维基链接到工作项。 想象一下这个功能,当你在维基页面上推荐史诗的每个特征时,你可以跟踪你的史诗完成百分比。 您可以尝试分享您的反馈。 VSTS Wiki now supports referencing work items using #. You can type # and reference an existing work item. This feature ...
  • 好吧,在我放弃和发布之后,我想通了。 我错误地使用了Contains。 我在括号中有过滤器。 以下两个示例现在都有效。 Select [System.Id], [System.Title], [System.State], [System.Tags] From WorkItems Where [State] <> 'Closed' AND [State] <> 'Removed' AND [Tags] Contains 'User Generated' AND [System.WorkItemType] = ...
  • 不,VSTS仅针对同一VSTS帐户提取请求链接的工作项。 这是因为我们可以在帐户中添加其他帐户,因此该帐户代表整个项目的所有连接。 对于您的情况,您需要在公司帐户中添加团队 ,而不是创建新帐户。 在新增的团队中,您仍然可以使用公司帐户其他团队的工作项。 No, VSTS pull request linked work items only for the same VSTS account. That’s because we can add other accounts in the account, ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)