Javascriptを使用してフォームを作成し、提出する方法
-
22-09-2019 - |
質問
私は家の中で使用されるのです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>
ここ
ないjavascriptのです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();
JSを使用してデータを送信するとき、は、私は、サーバーから次の例外を取得します。 例外
javax.servlet.ServletException:com.sun.jersey.api.container.ContainerException:javax.mail.MessagingException:行方不明開始境界
任意のアイデア?
解決
あなたはファイル入力の値を設定することはできません - 。そうでなければ、人々のマシンからファイルを盗むことができます。
他のヒント
私は、セキュリティ上の理由から<input type="file">
フィールドの値を変更することができるとは思いません。あなたはおそらくこれを自動化する別の方法を見つける必要があります。
所属していません StackOverflow