Reputation: 457
If you click on the bootstrap icon, you want to load the member list below the search bar without moving the page.
So I wrote the code this way.
AdminCotroller.java
// show AdminMainPage
@RequestMapping("adminPage.do")
public String adminPage(
@RequestParam(required = false) String keyword,
@RequestParam(defaultValue="0") int type,
HttpSession session,HttpServletRequest resquest,HttpServletResponse response) throws IOException
{
ModelAndView mav = new ModelAndView();
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("type", type);
params.put("keyword", keyword);
System.out.println(params);
return "adminMainPage";
}
// show_allMember Request
@RequestMapping("show_allMember.do")
public ModelAndView memberList()
{
ModelAndView mav = new ModelAndView();
mav.addObject("memberList", aService.getMemberList());
mav.setViewName("");
System.out.println("mav is : " + mav);
return mav;
}
The jsp file is shown below.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/swiper.min.css">
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/swiper.jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/adminMainPage.css">
<title>Insert title here</title>
</head>
<body>
<div class="adminMainPage">
<form action="kkk.do" name="form">
<div class="menu_btn_zone">
<div class="member_management_btn">
<a class="member_management">회원관리</a>
</div>
<div class="admin_setPermissions_btn">
<a class="admin_setPermissions">관리자 권한 설정</a>
</div>
</div>
<div class="member_management_area" style="display:none">
<div class="member_search">
<a class="member_search_zone">
<span class="glyphicon glyphicon-menu-hamburger searchMenuyo" aria-hidden="true"></span>
<span name="searchMenu" id="searchMenu">검색 유형을 선택하세요</span>
</a>
<input type="text" name="keyword">
<a class="memberSearch_bt">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</a>
<select id="choiceSearchMenu" name="type" onchange="menuDisplay(this.form)">
<option value="0"> ---- 선택하세요 ---- </option>
<option value="1">아이디로 검색</option>
<option value="2">끝 번호로 검색</option>
</select>
</div>
<div class="show_allMember" style="position: absolute;top: 155px;left: 1244px;font-size: 20px">
<span class="glyphicon glyphicon-user"></span><span class="show_all_member"><a onclick="location.href='show_allMember.do'" style="color: black;text-decoration:none">회원전체보기</a></span>
</div>
</div>
<div class="memberListZone" style="display:none">
- MEMBER LIST ZONE -
</div>
<div class="admin_setPermissions_area" style="display:none">
- Admin -
</div>
</form>
</div>
<script type="text/javascript">
$('.member_management').click(function()
{
$('.admin_setPermissions_area').css('display','none');
$('.member_management_area').css('display','block');
$('.member_management').css('color','#fe4978');
$('.admin_setPermissions').css('color','black');
});
$('.admin_setPermissions').click(function()
{
$('.member_management_area').css('display','none');
$('.admin_setPermissions_area').css('display','block');
$('.member_management').css('color','black');
$('.admin_setPermissions').css('color','#fe4978');
});
$('.searchMenuyo').click(function()
{
$('#choiceSearchMenu').slideDown();
});
$('#choiceSearchMenu').mouseout(function()
{
$('#choiceSearchMenu').slideUp();
});
function menuDisplay(frm)
{
var menu = frm.type.selectedIndex;
console.log(menu);
if(menu == 1)
{
document.getElementById('searchMenu').innerHTML='아이디로 검색';
}
if(menu == 2)
{
document.getElementById('searchMenu').innerHTML='끝 번호로 검색';
}
}
</script>
</body>
</html>
There are two menus at the top, if you look at the picture. When you click on the menu on the left, you will see a bootstrap emoticon and search bar.
The code for the right bootstrap icon is shown below.
<div class="show_allMember" style="position: absolute;top: 155px;left: 1244px;font-size: 20px">
<span class="glyphicon glyphicon-user"></span><span class="show_all_member"><a onclick="location.href='show_allMember.do'" style="color: black;text-decoration:none">회원전체보기</a></span>
</div>
My curiosity starts to explode from here.
How can I get only the values from the jsp by putting the values into the ModelAndView without moving the page?
How should the value be displayed when the menu is clicked and implemented?
Spring, ajax, jquery Advisors please give me advice or tell me your plan. If so, I would really appreciate it.
Upvotes: 1
Views: 2786
Reputation: 2144
If you don't want to reload the page every time you have to refresh data with ajax calls. To make this you have to write Spring methods that produces json.
You can simply do that tagging the method with produces = "application/json"
, adding all the data you need in jsp in Model
object and returning an empty string:
@RequestMapping(value = "/showAllMembers", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, method = RequestMethod.POST)
public String loadData(@RequestParam(value = "param1") String param1, @RequestParam(value = "param2") String param2, Model model){
List<Members> members = aService.getMemberList();
model.addAttribute("list", members);
return "";
}
In Spring you can add Model object to every method, is basically the same of ModelAndView and with addAttribute method you can pass what you want to jsp.
To call this method from the jsp use jquery ajax function:
function showMembers(){
// set the parameters you what
var data = { param1 : "param1", param2 : "param2"}
$.ajax({
//set correct url
url: localhost/path/showAllMembers,
type: 'post',
data: data,
success: function(response){
// response will contain every object you added in model object, so in this case list
$.each(response.list, function(index, value){
// do whatever you want with your data
});
});
}
Upvotes: 1