jsp
<%--
Created by IntelliJ IDEA.
User: 呆萌老师:QQ:2398779723
Date: 2019/12/6
Time: 15:55
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String baseurl=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
pageContext.setAttribute("baseurl",baseurl);
%>
<html>
<base href="${baseurl}" />
<head>
<title>Titletitle>
<script src="${baseurl}/static/js/jquery1.11.3.min.js">script>
<script src="${baseurl}/static/js/reg.js">script>
head>
<body>
<from action="${baseurl}/users/reg" method="post">
<pre>
用户名:<input type="text" name="uname" /><span id="s1">span>
密码:<input type="password" name="pwd" />
确认密码:<input type="password" name="repwd" />
专业:<select id="major" >
select>
<input type="submit" name="sub" value="注册" />
pre>
from>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
js
$(function(){
$(":text[name='uname']").blur(function(){
var uname=$(this).val();
$.get("http://localhost:8080/TestSpringMVC4/users/checkUname?uname="+uname,function(msg){
if(msg=="exists")
$("#s1").html("已存在");
else
$("#s1").html("可以使用");
})
})
$("#major").click(function(){
$.getJSON("http://localhost:8080/TestSpringMVC4/users/getMajorList2",function(arr){
$("#major").empty();
$.each(arr,function(k,v){
var option=$("");
option.val(v.id);
option.html(v.name);
$("#major").append(option);
})
})
})
})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
java
package com.test.controller;
import com.alibaba.fastjson.JSON;
import com.test.pojo.Major;
import com.test.pojo.Users;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping("/users")
public class UsersController {
@RequestMapping("/loginUi")
public String loginUi()
{
return "login";
}
@RequestMapping("/checkLogin")
public String checkLogin(Users user, HttpServletRequest request)
{
if(user.getUname().equals("daimenglaoshi") && user.getPwd().equals("123"))
{
HttpSession session= request.getSession();
session.setAttribute("loginUser",user);
return "redirect:/index.jsp";
}
else
return "login";
}
@RequestMapping("/regUi")
public String regUi()
{
return "reg";
}
@RequestMapping("/checkUname")
@ResponseBody
public String checkUname(String uname)
{
if(uname.equals("daimenglaoshi"))
return "exists";
else
return "not exists";
}
@RequestMapping("/getMajorList")
@ResponseBody
public List<Major> getMajorList()
{
List<Major> majorList=new ArrayList<Major>();
System.out.println("2222");
majorList.add(new Major(1,"aaa"));
majorList.add(new Major(2,"bb"));
return majorList;
}
@RequestMapping(value="/getMajorList2",produces = "text/html;charset=utf-8")
@ResponseBody
public String getMajorList2()
{
List<Major> majorList=new ArrayList<Major>();
majorList.add(new Major(1,"计算机"));
majorList.add(new Major(2,"英语"));
return JSON.toJSONString(majorList);
}
}

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
项目结构
