javascript - 使用 POST 将参数从脚本发送到 servlet

标签 javascript servlets

我有与 Web 焦点进程关联的 JavaScript 代码,该代码向我返回一些参数。我想将这些参数之一传递给我的 Servlet,但我不知道如何将此参数传递给我的 Servlet。我粘贴一些代码:

document.form1.INFCENTRO.value=9991;
document.form1.NOMBRENTI.value='DOCALIA';
document.form1.NOMBRENTI.disabled=true;
document.form1.NOMAPE.disabled=true;
document.form1.CLAVEUSU.value=user_espe;
document.form1.CLAVEUSU.disabled=true;
document.form1.FECHAPETI.disabled=true;

var pagina="http://lnxntf05:8080/MyMaver/ServletTipoPapel";

function redireccionar() 
{
    location.href=pagina;
} 
setTimeout ("redireccionar()", 20);

document.form1.CLAVEUSU 中,我获得了想要传递给 Servlet 的值,但我不知道如何...有人可以帮助我吗?

最佳答案

听起来您想发布该表单。如果是这样:

function redireccionar() {
    document.form1.method = "POST"; // Don't need this if it's in the markup
    document.form1.action = "http://lnxntf05:8080/MyMaver/ServletTipoPapel"; // Could put this in the markup as well
    document.form1.submit();
}

setTimeout(redireccionar, 20);

但是您需要禁用表单元素(删除 document.form1.CLAVEUSU.disabled=true 等),因为不会发送禁用的表单元素与表格。

<小时/>

请注意,通常最好不要将字符串与setTimeout一起使用。我使用了上面的函数引用。

关于javascript - 使用 POST 将参数从脚本发送到 servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17208142/

相关文章:

javascript - 输入的颜色如何计算背景颜色?

java - 想要添加表单字段并在servlet中获取它

java - 如何将一个ArrayList分解并显示为多个表列

javascript - 为什么 window.location.reload() 否定前面的命令?

javascript - 从 url 中删除 bootstrap 3 选项卡 href 哈希名称

javascript - 点击后渲染模板

java - Servlet 中的线程和并发

javascript - 客户端使用Crypto JS计算MD5哈希与终端计算不同

java - 内部 Servlet 映射 - web.xml

java - 从 http 到 https