问题描述
service():public class UserServiceImpl implements UserService {private UserDao userDao;public void setUserDao(UserDao userDao) {this.userDao = userDao;}public List<User> getAll() {return userDao.getAll();}jsp:<script type="text/javascript" src="/Demo_001/js/jquery-1.10.2.js"></script><script type="text/javascript">$(document).ready(function(){$("#bt").click(function(){$.post(url,data,calback);});});</script></head><body><a href="user_getAll.action">${count}人!</a><br><button type="button" id="bt">本页加载</button><div id="content"></div></body></html>帮忙详细指导,主要是想在jsp页面中的js通过jquery ajax对service()方法调用,并遍历list的值显示在<div id="content">中
解决方案
加个Controller层,把service注进来。e.g.【springmvc】@RequestMapping(value = "test/test.do", method = RequestMethod.GET)public String testMethod(HttpServletRequest request,HttpServletResponse response)throws WebControllerException {// service.XXX;}jsp $.get("XXXXX/test/test.do?param=1", function(data) {});大概这样
解决方案二:
后台封装成json前台$.post("XXXXX/test/test.do,{parm1:LZ,parm2:SB}, function(data) { },"json");
解决方案三:
public List<User> getAll() { return userDao.getAll(); } 把你的返回值改成json格式,前台解析json来显示。