Javascript 如何使用Java脚本创建和提交表单

Javascript 如何使用Java脚本创建和提交表单,javascript,web-services,firefox,multipartform-data,Javascript,Web Services,Firefox,Multipartform Data,我正在编写一个Firefox扩展,它将在内部使用。基本上,我需要向web服务提交一个pdf文件和一些文本值。现在,我有一个html页面可以这样做。我需要扩展来自动收集数据并将其提交到web服务 下面是html的工作原理 <body> <form name="frm_upload_file" enctype="multipart/form-data" method="post" action="my web service address"> <table cellp

我正在编写一个Firefox扩展,它将在内部使用。基本上,我需要向web服务提交一个pdf文件和一些文本值。现在,我有一个html页面可以这样做。我需要扩展来自动收集数据并将其提交到web服务

下面是html的工作原理

<body>
<form name="frm_upload_file" enctype="multipart/form-data" method="post" action="my web service address">
<table cellpadding="2" cellspacing="0" border="0">
    <tr>
        <td>ClientID</td>
    <td><input type="text" name="client_id" /></td>
</tr>

<tr>
   <td>HTML</td>
   <td><input type="text" name="html" /></td>
</tr>
<tr>
   <td align="right" class="inputtxt"> File: </td>
   <td class="inputtxt">

       <input name="pdf" type="file" />
   </td>
</tr>
<tr>
   <td align="left" colspan="2" class="inputtxt">
       <p><br /><input type="submit" name="submit" value="Submit" /></p>
   </td>
</tr>
</table>
当用js提交数据时,我从服务器上得到以下异常。 例外情况

javax.servlet.ServletException:com.sun.jersey.api.container.ContainerException:javax.mail.MessaginException:缺少开始边界


有什么想法吗?

出于安全原因,我认为您不能修改
字段的值。您可能需要找到另一种自动化方法。

您不能设置文件输入的值-否则您可能会从人们的机器上窃取文件。

我认为您无法创建和填充这样的文件字段。。。
postToURL: function(html, file) {
var form = content.document.createElement("form");
form.setAttribute("enctype", "multipart/form-data");
form.setAttribute("method", "post");
form.setAttribute("action", "address to my web service");

var clientIDField = document.createElement("input");
clientIDField.setAttribute("type", "text");
clientIDField.setAttribute("name", "client_id");
clientIDField.setAttribute("value", "123456");
form.appendChild(clientIDField);

var htmlField = document.createElement("input");
htmlField.setAttribute("type", "text");
htmlField.setAttribute("name", "html");
htmlField.setAttribute("value", html);
form.appendChild(htmlField);    

var fileField = document.createElement("input");
fileField.setAttribute("type", "file");
fileField.setAttribute("name", "pdf");
fileField.setAttribute("value", file);
form.appendChild(fileField);

content.document.body.appendChild(form);    
form.submit();