这个验证账号密码是哪里出错了?

乐之者v 2017-06-21 11:15:49
我想提取出表单里的内容,检查账号密码是否正确,然后跳转页面。。但是不管输入什么,都能够跳转。。
LoginAction.java

public class LoginServlet extends HttpServlet {

private static Logger logger = Logger.getLogger(LoginServlet.class);
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// super.doGet(req, resp);
String account=req.getParameter("textfield");
String password=req.getParameter("textfield2");
System.out.println("account:"+account+" password:"+password);
if("123".equals(account) && "123".equals("password")) {
resp.sendRedirect("index.html");
}
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
}
}



web.xml

<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.servlet.LoginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

下面是页面表单的一部分代码:

<tr>
<td width="24%"><div align="center"><font style="height:1;font-size:9pt; color:#bfdbeb;filter:glow(color=#1070a3,strength=1)">用户</font></div></td>
<td width="76%" height="25"><input type="text" name="textfield" style="width:125px; height:20px; background:#32a2e3; font-size:12px; border:solid 1px #0468a7; color:#14649f;"></td>
</tr>
<tr>
<td><div align="center"><font style="height:1;font-size:9pt; color:#bfdbeb;filter:glow(color=#1070a3,strength=1)">密码</font></div></td>
<td height="25"><input type="text" name="textfield2" style="width:125px; height:20px; background:#32a2e3; font-size:12px; border:solid 1px #0468a7; color:#14649f;"></td>
</tr>



不知为何,不管账号密码输入什么,都会跳转,根本没有检验。。
...全文
250 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
那年花 2017-06-22
  • 打赏
  • 举报
回复
当你用双引号下的password 这时候password是一个字符串 而不是一个bean
  • 打赏
  • 举报
回复
"123".equals(account) && "123".equals("password") 改为 "123".equals(account) && "123".equals(password)
自由自在_Yu 2017-06-22
  • 打赏
  • 举报
回复
timo001 2017-06-22
  • 打赏
  • 举报
回复
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } 另外doPost再掉他自己干嘛
千杯不醉476 2017-06-22
  • 打赏
  • 举报
回复
改为: if("123".equals(account) && "123".equals(password))
  • 打赏
  • 举报
回复
"123".equals(account) && "123".equals("password")
"123".equals("password") 这句话有问题,上面的代码不是 &&操作吗?这个不是应该怎么样都不能跳转吧。。。
timo001 2017-06-22
  • 打赏
  • 举报
回复
"123".equals("password") 永远不会成立
凭什么不拼 2017-06-22
  • 打赏
  • 举报
回复
"123".equals(account) && "123".equals("password")
改为
"123".equals(account) && "123".equals(password) 你这个应该是怎样都不会跳转吧?
雨临Lewis 2017-06-21
  • 打赏
  • 举报
回复
if("123".equals(account) && "123".equals("password")) 这一句有问题,短路与后边的 "123".equals("password")永远是false吧?,password为什么要加引号?

81,115

社区成员

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

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