Jsp getParameter返回null
请原谅我提前问了一些愚蠢的问题,但是这个快照片段不能正常工作。JSP打印出“null”,查找下面的代码:Jsp getParameter返回null,jsp,servlets,Jsp,Servlets,请原谅我提前问了一些愚蠢的问题,但是这个快照片段不能正常工作。JSP打印出“null”,查找下面的代码: <html> <head> <title></title> </head> <body> <form action="ServletController" method="post"> <input type="text"
<html>
<head>
<title></title>
</head>
<body>
<form action="ServletController" method="post">
<input type="text" name="invoice">
<input type="text" name="amount">
<input type="text" name="date">
<input type="submit">
</form>
</body>
</html>
${param.invoice}
服务控制
classes.ServletController
服务控制
/服务器控制器
如果我把scriplet代码放入JSP,JSP返回“null”,在EL情况下,JSP什么也没有。我试着用HTML表单做实验,因为我认为问题在于浏览器没有正确地发出请求,但什么都没有。请告诉我错误在哪里,以及${}不起作用的原因。谢谢大家! 我的浏览器隐式地做到了这一点,也许你的浏览器没有 在您的
表格中添加enctype
<form action="ServletController" method="post" enctype="application/x-www-form-urlencoded">
因此,浏览器将表单元素序列化为application/x-www-form-urlencoded
内容,您可以使用HttpServletRequest#getParameter(String)
同意Sotirios Delimanolis的观点,大多数案例都包含在他的解决方案中,除此之外,请检查请求URL中要形成的多个参数
<input type="hidden" name="regId" id="regId" />
这将创建regId的两个值,服务器将假定它是一个数组,request.getParameter将返回null,request.getParameterValues将返回字符串数组。Sotirios,非常感谢!它起作用了!之前版本的Chrome没有enctype-attribute.Tiny,谢谢你的支持
<servlet>
<servlet-name>ServContr</servlet-name>
<servlet-class>classes.ServletController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServContr</servlet-name>
<url-pattern>/ServletController</url-pattern>
</servlet-mapping>
</servlet>
<form action="ServletController" method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="regId" id="regId" />
function fnSubmit()
{
document.getElementById("btnSubmit").disabled=true;
document.forms[0].action="someURL®Id=2";
document.forms[0].submit();
}