form提交的参数问题?

dyz2 2003-05-28 10:00:15
不论输入框中是否填入数值,用request.getParameter获得的值都不为null?
怎么回事? 源码如下

----------form file-----------
<html>
<head>
<title>index page</title>
</head>
<body>

<form action=hello.jsp method=get>
firstname:<input type="text" name="firstname"
value="default">
<input type="submit" value="login" >
</form>

</body>
</html>

------------hello.jsp---------
<html>
<head>
<title>hello page</title>
</head>
<body>

<%if (request.getParameter("firstname")==null){

out.println("Please enter your name.");
}%>

</body>
</html>

...全文
19 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyz2 2003-05-28
  • 打赏
  • 举报
回复
Thanks!
My final version is:

<%if (request.getParameter("firstname").equals("")){
out.println("Please enter your name.");
}%>
wellsoon 2003-05-28
  • 打赏
  • 举报
回复
null,

"";

"null",

是不同的东西。

if ((request.getParameter("firstname")!=null)&&(request.getParameter("firstname").length()>0)
{
}

else{
out.println("Please enter your name.");

}
yophoo 2003-05-28
  • 打赏
  • 举报
回复
呵呵,是不是该改成这样:
String firstname=request.getParameter("firstname")
然后用
if(firstname.equals(""))来进行判断?


luckyfanjian 2003-05-28
  • 打赏
  • 举报
回复
对,只要上一个页面传来firstname,这样页面就能得到,如果上一个页面传来null
这样页面得到的是:"null"
判断为空可以这样:request.getParameter("firstname").equals("null")

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧