如何把JSP页面的URL参数传到JAVA后台去???

emit emit 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
JSP页面:
<script type="text/javascript">
<!--function run(){
var strTxt1 = document.forms[0].txt1.value;//document.getElementsByName("txt1").value;
var strTxt2 = document.getElementsByName("txt2");
document.forms[0].action="user.do?txt1=strTxt1&txt2=strTxt2";
document.forms[0].submit();

}
//-->
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<form action="" method = "post" onsubmit="return false">
<input type="text" name ="txt1">
<input type="text" name ="txt2">
<input type="button" value ="submit" onclick="run()">

</form>
</body>
</html>


问题:
document.forms[0].action="user.do?txt1=strTxt1&txt2=strTxt2";
这种写法在JAVA里执行 String txt1 = (String)request.getAttribute("txt1");
总是Null,怎么去jsp表单里txt1和txt2的值啊???
PS:用Struts的ActionForm这种做法当然能解决,我现在就是想用URL这种方法来取这些参数,请大侠们赐教,不胜感激
...全文

相关推荐

评论 20
收藏 已收藏
分享
返回顶部
emit
Web 开发 81,108 成员 341,721 内容