Server side equivalent of Window.Location.getParameter() in GWT
On the client side I am able to retrieve URL parameters in GWT by
String parameterName = Window.Location.getParameter("parameterName");
Doing the same server side however gives me this exeption:
[...]
threw an unexpected exception: java.lang.ExceptionInInitializerError
[...]
Caused by: java.lang.ExceptionInInitializerError
at com.google.gwt.user.client.Window$Location.getQueryString(Window.java:262)
at com.g开发者_开发百科oogle.gwt.user.client.Window$Location.ensureParameterMap(Window.java:321)
at com.google.gwt.user.client.Window$Location.getParameter(Window.java:211)
at com.icada.idea.server.CurrentUser.getUser(CurrentUser.java:31)
Where line 31 in CurrentUser reads:
String noLogin= Window.Location.getParameter("nologin");
So how do I get the URL parameter server side? Or is it the only way to pass as a parameter to the method I am calling?
On the server side, you don't have a Window. All you get from the client is a request - and that request may contain parameters (GET parameters or POST parameters).
You can retrieve them by using
request.getParameter("parameterName");
The request is available in Servlets, e.g. in the doGet(HttpServletRequest request, HttpServletResponse response)
and doPost(HttpServletRequest request, HttpServletResponse response)
methods.
If you're using GWTRPC, you could use getThreadLocalRequest()
, but as you usually don't post the Window's parameters as POST parameters with a GWTRPC call, it would be more natural to pass the parameters you require as method parameters.
精彩评论