5
我想在GWT應用程序中獲得會話屬性。我得到會話這樣HttpServletRequest request = this.getThreadLocalRequest()return null?
HttpServletRequest request = this.getThreadLocalRequest();
System.out.println("Check HttpServletRequest");
HttpSession session = request.getSession();
但this.getThreadLocalRequest()
總是null
。
CODE:
客戶:
@RemoteServiceRelativePath("service.s3gwt")
public interface getAttributeSession extends RemoteService
{
String getSessionAttribute(String name);
}
public interface getAttributeSessionAsync
{
void getSessionAttribute(String name, AsyncCallback<String> callback);
}
服務器:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import daTotNghiep.client.service.getAttributeSession;
public class getAttributeSessionImpl extends RemoteServiceServlet implements getAttributeSession
{
private static final long serialVersionUID = 1L;
public String getSessionAttribute(String name)
{
// TODO Auto-generated method stub
HttpServletRequest request = this.getThreadLocalRequest();
System.out.println("Check HttpServletRequest");
if(request == null) System.out.println("SO BAD");
// HttpSession session = request.getSession();
// System.out.println("ID session "+session.getId());
return "";
}
}
當調用方法getSessionAttribute()
我看到this.getThreadLocalRequest()
總是返回null
。所以爲什麼?以及如何解決它?
你已經解決了嗎? – kozla13