Heim > Fragen und Antworten > Hauptteil
请大神帮忙编写代码 跪谢
@Controller
@RequestMapping("/*")
public class UserAction {
@RequestMapping("login.action")
public String login(HttpSession session,String username,String password,RedirectAttributes ra,String yzm){
Map<String, Object> parmas=new HashMap<String, Object>();
String sessionYzm=(String) session.getAttribute("verCode");
if(yzm.toLowerCase().equals(sessionYzm)){
}else{
return "redirect:/jsp/login.jsp";
}
parmas.put("logname", username);
parmas.put("logpwd", password);
User user=userService.slectUserByLognameAndLogpwd(parmas);
if(user==null){
return "redirect:/jsp/login.jsp";
}
String name=user.getLogname();
String pass=user.getLogpwd();
if(username.equals(name)&& password.equals(pass)){
return "main";
}else{
return "redirect:/jsp/login.jsp";
}
}
}
jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>登陆页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" href="css/bace.css">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/login.css">
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<p class="wrapper">
<!-- 头部logo -->
<header>
<img src="images/1.png" alt="logo" class="logo">
<img src="images/2.png" alt="舆情查询系统" class="title">
</header>
<!-- 内容登录区域 -->
<section style="">
<p class="nav">
<!-- 内容区域logo标志 -->
<img src="images/1.png" alt="">
</p>
<p class=""><span></span>用户登录<i></i></p>
<form action="login.action" method="post" id="myForm" novalidate="novalidate">
<p class="mt15">
<label for="">用户名: </label><input type="text" name="username" value="" placeholder="请输入账号" required="required"
maxlength="20" data-msg-maxlength="用户名最多为20个字符" data-msg-required="用户名不能为空"
minlength="2" data-msg-minlength="用户名最少为2个字符" >
</p>
<p class="mt15">
<label for="" style="margin-right:2px;">密 码: </label><input type="text" name="password" value="" placeholder="" class=""
required="required" maxlength="20" data-msg-maxlength="密码最多为20个字符" data-msg-required="密码不能为空" minlength="2" data-msg-minlength="密码最少为2个字符" >
<a href="" class="col_el3 p10" >忘记密码</a>
</p>
<p class="mt15 ">
<label for="">验证码: </label><input type="text" name="yzm" value="" class="mr15 w90" required="required"
maxlength="4" data-msg-maxlength="密码为4个字符" data-msg-required="密码不能为空"
minlength="4" data-msg-minlength="密码为4个字符" >
<!-- <p id="msg">
</p> -->
<img id="yzm" alt="点击刷新" title="点击刷新" src="creatYzm.action" style="height: 30px;width: 74px;position: absolute;cursor:pointer" onclick="refresh()">
</p>
<p class="mt40 btn ml10" >
<input type="submit" value="注册" class="mr15" >
<input type="submit" value="登录" class="" >
</p>
</form>
</section>
<!-- 底部的版权 -->
<footer>
<img src="images/3.png" alt="">
</footer>
</p>
</body>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript" src="js/messages_cn.js"></script>
<script type="text/javascript">
function refresh(){
var refreshUrl="creatYzm.action?"+new Date();
$("#yzm").attr("src",refreshUrl);
}
$().ready(function() {
$("#myForm").validate();
});
</script>
</html>
巴扎黑2017-04-11 09:12:45
代码就不帮你编写了。只是简单说一下,你完全可以采用异步的方式登陆,请求的时候做好加密等安全性措施的处理。后台处理玩后再在异步的回调里处理,成功跳转到你想去的画面,失败给出提示。
另外springmvc的@RequestMapping 写的是请求的url,你这么写【@RequestMapping("login.action")】.action应该交给spring去拦截。