比如@Ok("jsp:hello.jsp")
方法体中return的数据我怎么在hello.jsp接收
21 回复
@At
@POST
@Ok(">>:/WebRoot/hello.jsp")
public User select(String name,HttpSession session){
Cnd cnd = Cnd.where("name", "like", "%"+name+"%");
List<User> list = dao.query(User.class, cnd);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getName());
}
User user = new User();
user.setId(6);
user.setName("zhaoliu");
user.setPassword("ewqeqweqw");
session.setAttribute("user", user);
return user;
}
<!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=UTF-8">
<title>NutzBook demo</title>
<!-- 导入jquery -->
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js"></script>
<!-- 把user id复制到一个js变量 -->
<script type="text/javascript">
var me = '0';
var base = '/nutzbook';
$(function() {
});
</script>
net.wendal.nutzbook.bean.User@5cf12eb4
</head>
<body>
net.wendal.nutzbook.bean.User@5cf12eb4
</body>
</html>
@At
@POST
@Ok("jsp:jsp.hello")
public User select(String name,HttpSession session){
Cnd cnd = Cnd.where("name", "like", "%"+name+"%");
List<User> list = dao.query(User.class, cnd);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getName());
}
User user = new User();
user.setId(6);
user.setName("zhaoliu");
user.setPassword("ewqeqweqw");
session.setAttribute("user", user);
return user;
}
请求页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>NutzBook demo</title>
<!-- 导入jquery -->
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js"></script>
<!-- 把user id复制到一个js变量 -->
<script type="text/javascript" src="./js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="./js/jquery-1.8.3.min.js"></script>
</head>
<body>
名字:<input type="text" id="i"/>
<button type="button" onclick="submi()">提交</button>
<script type="text/javascript">
var base = '${base}';
function submi(){
var startDat=$("#i").val();
alert(startDat);
$.ajax({
url:'${base}'+ "/user/select",
type: "post",
data:{"name":startDat},
dataType : "json",
success: function(data) {
alert(data);
}
});
};
</script>
</body>
</html>
接收页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>NutzBook demo</title>
<!-- 导入jquery -->
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js"></script>
<!-- 把user id复制到一个js变量 -->
<script type="text/javascript">
var me = '<%=session.getAttribute("me") %>';
var base = '${base}';
$(function() {
});
</script>
<%=request.getAttribute("obj")%>
</head>
<body>
<%=request.getAttribute("obj")%>
</body>
</html>
添加回复
请先登陆