日期:2014-05-17  浏览次数:20949 次

关于HttpServletRequest和ServletRequest的相关问题
这里随便贴了一个Servlet
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
List<Userbean> list = new ArrayList<Userbean>();
List course = new ArrayList();
String username = request.getParameter("txt1");
String password = request.getParameter("psd1");
QueryUser login=new QueryUser();
GetCourseInfo gti = new GetCourseInfo();
list = login.search(username, password, null);
course = gti.getCourseinfo(username);
if (list.size() != 0) {

request.getSession().setAttribute("course", course);// 将查询到的课程信息返回到jsp主页

Userbean user = new Userbean();
user.setUsername("student");
request.getSession().setAttribute("student", user);
request.setAttribute("list", list);
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("/index.jsp");
requestDispatcher.forward(request, response);
}
if (list.size() == 0) {
request.setAttribute("list", list);
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("./user/wrong.jsp");
requestDispatcher.forward(request, response);
}

}
}

这里的参数是HttpServletRequest的request,但是在跳转的时候为什么可以写request.getRequestDispatcher("./user/wrong.jsp");呢?getRequestDispatcher这个方法明明是ServletRequest这个接口的HttpServletRequest这个接口里也有这么方法?费解

求指导


------解决方案--------------------
HttpServletRequest 继承了 ServletRequest 接口 接口也可以继承的~~