[英]Making href (anchor tag) request POST instead of GET as passing the parameter
[英]Passing request parameter with href without they visible in request (Making href Post instead of Get)
我的JSP中有一个html表,其中一列是锚元素。单击此锚标签后,我需要调用Servlet。在此请求中,将文件名作为请求参数与Servlet调用一起附加到上。 喜欢
<table>
<tr><td>
<a href="/FileDownLoadServlet.dwnld?fileName=Test1.pdf&key=123456" target="_blank">Test1Container</a>
<td></tr>
<tr><td>
<a href="/FileDownLoadServlet.dwnld?fileName=Test2.pdf&key=789123" target="_blank">Test2Container</a>
<td></tr>
</table>
servlet中写入文件以响应,因此在新选项卡中打开了相应的pdf。
问题是在其地址栏中打开的新标签页显示了整个URL。可能是由于href请求GET所致。 我想避免这种情况,并显示不带servlet名称及其请求参数的原始URL。如果可能的话,可能在上下文名称之后仅在地址栏中显示文件名。 请提出建议。
JS小提琴: http : //jsfiddle.net/9qacod03/
<form id = "pdfViewer" method = "post" action = "/FileDownLoadServlet.dwnld" target="_blank">
<input type = "hidden" name = "fileName" value = "" />
<input type = "hidden" name = "key" value = "" />
</form>
<table>
<tr>
<td>
<a class = "pdfLink" fileName = "Test1.pdf" key = "123456" href = "#">Test1Container</a>
</td>
</tr>
<tr>
<td>
<a class = "pdfLink" fileName = "Test2.pdf" key = "789123" href = "#">Test2Container</a>
<td>
</tr>
</table>
$(".pdfLink").click(function () {
var fileName = $(this).attr("fileName");
var key = $(this).attr("key");
$("#pdfViewer").find("[name=fileName]").val(fileName);
$("#pdfViewer").find("[name=key]").val(key);
$("#pdfViewer").submit();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.