为什么在serlvet层会提示queryMessageList(String,String)这个方法不存在呢?
为什么在serlvet层会提示queryMessageList(String,String)这个方法不存在呢?
//service层代码
package com.imooc.service;
import java.util.List;
import com.imooc.bean.Message;
import com.imooc.dao.MessageDao;
/*
* 列表相关的业务功能,因为一般不直接调dao层的,都是要经过service来调用
*/
public class ListService {
public List<Message> queryMessageList(String command,String description){
MessageDao messageDao=new MessageDao();
return messageDao.queryMessageList(command, description);
}
}
//servlet层代码
package com.imooc.servlet;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.imooc.bean.Message;
import com.imooc.service.ListService;
/**
*列表页面的初始化
*
*/
@SuppressWarnings("serial")
public class ListServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//设置编码
req.setCharacterEncoding("UTF-8");
//接受页面的值
String command=req.getParameter("command");
String description=req.getParameter("description");
//向页面传值
req.setAttribute("command", command);
req.setAttribute("description", description);
ListService listService=new ListService();
List<Message> messageList=new ArrayList<Message>();
messageList=listService.queryMessageList(command, description);
req.setAttribute("messageList", messageList);
//在上面用jdbc把数据库取出来之后放在messageList里面,然后就可以转发了,转发到由req带到前台去使用请求转发,就是servlet那里传过来的请求会直接转给这个页面来处理
req.getRequestDispatcher("/WEB-INF/jsp/background/list.jsp").forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
}
}