注册时 跳转到注册页面就出现400报错
尝试过的解决方式:
1.清除缓存
2.重构项目
3.检查所有的username属性是否有拼写错误
4.根据其他回答重写controller里的注册代码,将密码检验分离到jsp页面中
无论咋改 还是报这个400错误 烦请老师帮忙看一下有什么问题
可能是我自己有没检查到的地方
User.java:
package com.imooc.bbs.entity;
public class User {
private int id;
private String username;
private String password;
private String email;
//注册时状态的值为0,表示正常账户。当后台进行锁定操作时,该状态变为1。在进行删除时,该状态变为2。
private int userStatus;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getUserStatus() {
return userStatus;
}
public void setUserStatus(int userStatus) {
this.userStatus = userStatus;
}
}
UserDao.java:
package com.imooc.bbs.dao;
import com.imooc.bbs.entity.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository("userDao")
public interface UserDao {
void insert(User user);
void update(User user);
void delete(int id);
User selectById(int id);
User selectByName(String username);
List<User> selectAll();
}
GlobalBiz.java:
package com.imooc.bbs.biz;
import com.imooc.bbs.entity.User;
public interface GlobalBiz {
User login(String username, String password);
void register(User user);
}
GlobalBizImpl.java:
package com.imooc.bbs.biz.impl;
import com.imooc.bbs.biz.GlobalBiz;
import com.imooc.bbs.dao.UserDao;
import com.imooc.bbs.entity.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service("globalBiz")
public class GlobalBizImpl implements GlobalBiz {
@Autowired(required = false)
private UserDao userDao;
public User login(String username,String password) {
User user = userDao.selectByName(username);
if (user != null && user.getPassword().equals(password)) {
return user;
}
return null;
}
public void register(User user) {
userDao.insert(user);
}
}
GlobalController.java:
package com.imooc.bbs.controller;
import com.imooc.bbs.biz.GlobalBiz;
import com.imooc.bbs.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.Map;
@Controller("globalController")
public class GlobalController {
@Autowired
private GlobalBiz globalBiz;
@RequestMapping("/to_login")
public String toLogin() {
return "/login";
}
@RequestMapping("/login")
public String login(HttpSession session, @RequestParam String username, @RequestParam String password) {
User user = globalBiz.login(username, password);
if (user == null) {
return "redirect:to_register";
}
session.setAttribute("user", user);
return "list";
}
@RequestMapping("/to_register")
public String toRegister(){
return "register";
}
@RequestMapping("/register")
public String register(User user,@RequestParam String username,@RequestParam String password,@RequestParam String email){
user.setUsername(username);
user.setPassword(password);
user.setEmail(email);
user.setUserStatus(0);
globalBiz.register(user);
return "redirect:to_login";
}
}
register.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>慕课论坛</title>
<link rel="stylesheet" href="../../static/css/all-df86af5803.css">
<script type="text/javascript">
function validate_form() {
var password =document.getElementsByName("password").value;
var password2=document.getElementsByName("password_confirm").value;
if(password!=password2){
alert("两次密码不一致");
return false;
}
return true;
}
</script>
</head>
<body class="forum" data-page="forum">
<div class="header">
<nav class="navbar navbar-inverse navbar-fixed-top navbar-default">
<div class="container">
<div class="navbar-header" id="navbar-header">
<a href="index.html" class="navbar-brand"><img src="../../images/logo.png">
</a>
</div>
<div id="main-nav-menu">
<ul class="nav navbar-nav">
<li ><a href="list.jsp"><i class="fa fa-home"></i> <span class="hidden-xs hidden-sm">首页</span></a></li>
<li class="hidden-sm hidden-xs"><a href="thread.jsp"><i class="fa fa-comments-o"></i> 话题</a></li>
</ul>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="nav-search hidden-xs hidden-sm">
<form method="GET" action="###/auth/register" accept-charset="UTF-8" class="navbar-form form-search active" target="_blank">
<div class="form-group">
<input placeholder="搜索" class="form-control" name="q" type="search">
</div>
<i class="fa fa-search"></i>
</form>
</li>
<li class="active"><a href="register.jsp" id="signup-btn">注册</a></li>
<li ><a href="login.jsp" id="login-btn">登录</a></li>
</ul>
</div>
</nav>
</div> <div id="main" class="main-container container">
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading">注册</div>
<div class="panel-body">
<form role="form" method="POST" action="register" onsubmit="return validate_form()">
<div class="form-group">
<input type="text" class="form-control" name="username" id="username" placeholder="用户名">
</div>
<div class="form-group">
<input type="text" class="form-control" name="email" id="email" placeholder="邮箱地址">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" id="password" placeholder="密码">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password_confirm" placeholder="确认密码">
</div>
<button type="submit" class="btn btn-primary">
注册
</button>
<a href="" class="btn btn-default">取消</a>
</form>
</div>
</div>
<div class="panel-footer">
已注册或使用社交账号登录,请点击 <a href="login.jsp">这里</a> 进行登录。
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<div class="copyright">
<blockquote class="pull-left">
<p>慕课论坛</p>
<p>Copyright © 2015-2016 <a href="list.jsp">imooc</a> 1.0.0-rc2 <span class="pipe">|</span><span class="pipe">|</span></p>
</blockquote>
</div>
<div class="pull-right hidden-sm hidden-xs">
<p>
<a href="###">关于我们</a>
<span class="pipe">|</span>
<a href="###">联系我们</a>
<span class="pipe">|</span>
<a href="###">常见问题解答</a>
</p>
<p>
<a href="list.jsp" target="_blank"><img src="../../images/imooc-logo.png" border="0" height="40" data-toggle="tooltip" data-placement="top" title="Powered by imooc" /></a>
</p>
</div>
</div>
</footer>
</body>
</html>
login.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>慕课论坛</title>
<link rel="stylesheet" href="../../static/css/all-df86af5803.css">
</head>
<body class="forum" data-page="forum">
<div class="header">
<nav class="navbar navbar-inverse navbar-fixed-top navbar-default">
<div class="container">
<div class="navbar-header" id="navbar-header">
<a href="list.jsp" class="navbar-brand"><img src="../../images/logo.png">
</a>
</div>
<div id="main-nav-menu">
<ul class="nav navbar-nav">
<li ><a href="list.jsp"><i class="fa fa-home"></i> <span class="hidden-xs hidden-sm">首页</span></a></li>
<li class="hidden-sm hidden-xs"><a href="thread.jsp"><i class="fa fa-comments-o"></i> 话题</a></li>
</ul>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="nav-search hidden-xs hidden-sm">
<form method="GET" action="/bbs/preLogin.do" accept-charset="UTF-8" class="navbar-form form-search active" target="_blank">
<div class="form-group">
<input placeholder="搜索" class="form-control" name="q" type="search">
</div>
<i class="fa fa-search"></i>
</form>
</li>
<li ><a href="register.jsp" id="signup-btn">注册</a></li>
<li class="active"><a href="login.jsp" id="login-btn">登录</a></li>
</ul>
</div>
</nav>
</div> <div id="main" class="main-container container">
<div class="container-fluid">
<div class="row">
<div class="col-md-5 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">登录</div>
<div class="panel-body">
<form role="form" method="POST" action="login">
<div class="form-group">
<input type="login" class="form-control" name="username" value="" placeholder="用户名">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="密码">
</div>
<div class="form-group">
<input type="submit" name="commit" value="登录" class="btn btn-primary btn-lg btn-block">
</div>
</form>
</div>
<div class="panel-footer">
<a href="/register.jsp">注册</a>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">用其他平台的帐号登录</div>
<ul class="list-group">
<li class="list-group-item">
<a href="###" class="btn btn-default btn-lg btn-block"><i class="fa fa-github"></i> Github</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<div class="copyright">
<blockquote class="pull-left">
<p>慕课论坛</p>
<p>Copyright © 2015-2016 <a href="list.jsp">imooc</a> 1.0.0-rc2 <span class="pipe">|</span><span class="pipe">|</span></p>
</blockquote>
</div>
<div class="pull-right hidden-sm hidden-xs">
<p>
<a href="###">关于我们</a>
<span class="pipe">|</span>
<a href="###">联系我们</a>
<span class="pipe">|</span>
<a href="###">常见问题解答</a>
</p>
<p>
<a href="list.jsp" target="_blank"><img src="../../images/imooc-logo.png" border="0" height="40" data-toggle="tooltip" data-placement="top" title="Powered by imooc" /></a>
</p>
</div>
</div>
</footer>
</body>
</html>
list.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>慕课论坛</title>
<link rel="stylesheet" href="../../static/css/all-df86af5803.css">
</head>
<body class="forum" data-page="forum">
<div class="header">
<nav class="navbar navbar-inverse navbar-fixed-top navbar-default">
<div class="container">
<div class="navbar-header" id="navbar-header">
<a href="/bbs/list.do" class="navbar-brand"><img src="../../images/logo.png">
</a>
</div>
<div id="main-nav-menu">
<ul class="nav navbar-nav">
<li class="active"><a href=""><i class="fa fa-home"></i> <span
class="hidden-xs hidden-sm">首页</span></a></li>
<li class="hidden-sm hidden-xs"><a href="thread.html"><i class="fa fa-comments-o"></i> 话题</a></li>
</ul>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="nav-search hidden-xs hidden-sm">
<form method="GET" action="###" accept-charset="UTF-8"
class="navbar-form form-search active" target="_blank">
<div class="form-group">
<input placeholder="搜索" class="form-control" name="q" type="search">
</div>
<i class="fa fa-search"></i>
</form>
</li>
<!-- 登录成功要显示的内容 -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
imooc1 <!-- 此处显示用户名 -->
<span class="caret"></span></a>
<button class="navbar-toggle" type="button" data-toggle="dropdown" role="button" aria-expanded="false">
<span class="sr-only">Toggle</span>
<i class="fa fa-reorder"></i>
</button>
<ul class="dropdown-menu" role="menu"><li class=""><a href="my.html">我的主页</a></li>
<li><div class='divider'></div></li>
<li><a href="my.html">个人设置</a></li>
<li><a href="score.html">我的积分</a></li>
<li class='divider'></li>
<li><a href="###" onclick=" return confirm('你确定要退出吗?')"><i class="fa fa-sign-out"></i> 退出
</a></li>
</ul>
</li>
<!-- 未登录显示的内容 -->
<li><a href="/bbs/preReg.do" id="signup-btn">注册</a></li>
<li><a href="/bbs/preLogin.do" id="login-btn">登录</a></li>
</ul>
</div>
</nav>
</div>
<div id="main" class="main-container container">
<!-- 首页通栏(4个推荐位) -->
<div class="col-md-9 threads-index main-col">
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-left hidden-sm hidden-xs">
<i class="fa fa-list"></i> 首页
</div>
<ul class="pull-right list-inline remove-margin-bottom thread-filter">
<li>
<a href="thread.html">
<i class="fa fa-history"></i> 最新话题
</a>
</li>
<li>
<a href="thread.html">
<i class="fa fa-diamond"> </i> 优质帖子
</a>
</li>
<li>
<a href="thread.html">
<i class="fa fa-thumbs-o-up"> </i> 最多按赞
</a>
</li>
<li>
<a href="thread.html">
<i class="fa fa-eye"></i> 等待回复
</a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="panel-body remove-padding-horizontal">
<ul class="list-group row thread-list">
<!-- 显示帖子,每个li显示一个帖子的内容 -->
<li class="list-group-item media " style="margin-top: 0px;">
<a class="pull-right" href="post.html"><span class="badge badge-reply-count"> 25 </span>
</a>
<div class="avatar pull-left">
<a href="post.html">
<img class="media-object img-thumbnail avatar-48" alt="imooc" src="../../images/avatar.jpg"/>
</a>
</div>
<div class="infos">
<div class="media-heading">
<i class="fa fa-thumb-tack text-danger"></i>
<%-- <a href="/bbs/getPost.do?id=<%=post.getId()%>" title="<!-- 此处存放帖子标题的内容 -->">--%>
帖子标题 <!-- 此处显示帖子标题 -->
</a>
</div>
<div class="media-body meta">
<a href="post.html">
<span class="fa fa-thumbs-o-up"> 10 </span>
</a>
<span> • </span>
<span>回复</span>
<a href="post.html">
用户名
</a>
<span> • </span>
<span class="timeago " data-toggle="tooltip" data-placement="top"
title="2017-02-08 21:47:25">2017-02-08 21:47:25</span>
</div>
</div>
</li>
</ul>
</div>
<div class="panel-footer text-right remove-padding-horizontal pager-footer">
<!-- Pager -->
<!-- 如有需要可以在此处添加分页,本次作业不要求完成 -->
<ul class="pagination">
<li> <a href=""><span></span></a></li>
</ul>
</div>
</div>
</div>
<div class="col-md-3 side-bar">
<div class="panel panel-default corner-radius">
<div class="panel-heading">
<h3 class="panel-title">BBS</h3>
</div>
<!-- 登录后显示的内容 -->
<div class="panel-body text-center">
<a href="" class="btn btn-primary">
<i class="fa fa-user"> </i> 发帖
</a>
</div>
<!-- 未登录显示的内容 -->
<div class="panel-body text-center">
<a href="" class="btn btn-primary">
<i class="fa fa-user"> </i> 注册
</a>
</div>
<div class="panel-footer text-center">
已注册用户请 <a href="">登录</a>
</div>
</div>
<div class="panel panel-default corner-radius">
<div class="panel-heading">
<h3 class="panel-title">热门标签</h3>
</div>
<div class="panel-body">
<div class="badge badge-tag-cloud">
<a href="">Java</a> <a href="">Python</a>
</div>
</div>
</div>
<div class="panel panel-default corner-radius">
<div class="panel-heading">
<h3 class="panel-title">小贴士</h3>
</div>
<div class="panel-body">
猪有猪的思想,人有人的思想。如果猪有人的思想,那它就不是猪了——是八戒!
</div>
</div>
<div class="panel panel-default corner-radius">
<div class="panel-heading">
<h3 class="panel-title">统计信息</h3>
</div>
<ul class="list-group">
<li class="list-group-item">社区会员: 747</li>
<li class="list-group-item">主题数: 95</li>
<li class="list-group-item">回帖数: 218</li>
</ul>
</div>
</div>
<div class="clearfix"></div>
</div>
<footer class="footer">
<div class="container">
<div class="copyright">
<blockquote class="pull-left">
<p>慕课论坛</p>
<p>Copyright © 2015-2016 <a href="index.html">imooc</a> 1.0.0-rc2 <span class="pipe">|</span><span class="pipe">|</span></p>
</blockquote>
</div>
<div class="pull-right hidden-sm hidden-xs">
<p>
<a href="###">关于我们</a>
<span class="pipe">|</span>
<a href="###">联系我们</a>
<span class="pipe">|</span>
<a href="###">常见问题解答</a>
</p>
<p>
<a href="index.html" target="_blank"><img src="../../images/imooc-logo.png" border="0" height="40"
data-toggle="tooltip" data-placement="top"
title="Powered by imooc"/></a>
</p>
</div>
</div>
</footer>
</body>
</html>
17
收起
正在回答 回答被采纳积分+1
2回答
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星