package com.law.service;
import javax.servlet.http.HttpSession;
public class CountService {
public int count(){
HttpSession session = request.getSession();
}
}
为什么request出错 ,
------解决方案--------------------
public class ServletName extends HttpServlet {public void doPost(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
}
看看
------解决方案--------------------
request对象在哪里,这个变量从哪里来的,怎么能这样使用
------解决方案--------------------
request对象没有定义当然报错.
试试:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class CountService {
private HttpServletRequest request;
public HttpServletRequest getRequest() {
return request;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
public int count(){
HttpSession session = request.getSession();
}
}