我如何在@service类中获得HttpServletRequestObject [英] How do I get HttpServletRequestObject in the @service class
问题描述
我成功地整合了Spring和Spring4GWT。
一切正常。
我唯一遇到的问题是如何得到 HttpServletRequestObject
在 @service
类中?
一些配置和代码
web.xml
< servlet>
< servlet-name>测试< / servlet-name>
< servlet-class> org.spring4gwt.server.SpringGwtRemoteServiceServlet< / servlet-class>
1< / load-on-startup>
< / servlet>
< servlet-mapping>
< servlet-name>测试< / servlet-name>
< url-pattern> / ui / test / *< / url-pattern>
< / servlet-mapping>
服务类别
public class LoginServiceImpl实现ILoginService {
private IUserService userService;
public LoginServiceImpl(IUserService userService){
super();
this.userService = userService;
$ b $ public boolean isAuthenticUser(String userName,String password){
// operation
}
}
$ c $在 LoginServiceImpl
中我无法获得Servlet对象。
我在这里需要它,以便我可以将它用于不同的目的。
任何想法?
解决方案最后,我得到了一个解决方案。
如果有人想要在GWT-RPC服务中访问HttpServletrequest,那么以下内容可以提供帮助。
修改web.xml
< filter>
< filter-name> springRequestFilter< / filter-name>
< filter-class> org.springframework.web.filter.RequestContextFilter< / filter-class>
< / filter>
< filter-mapping>
< filter-name> springRequestFilter< / filter-name>
< url-pattern> / your_pattern / *< / url-pattern>
< / filter-mapping>
服务中
ServletRequestAttributes sra =((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes());
sra.getRequest();
希望这有帮助
I'm successfully able to integrate Spring and Spring4GWT.
Everything is working fine.
The only problem I'm facing is How do I get HttpServletRequestObject
in the @service
class?
Some of the configuration and code
web.xml
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/ui/test/*</url-pattern>
</servlet-mapping>
Service class
public class LoginServiceImpl implements ILoginService {
private IUserService userService;
public LoginServiceImpl(IUserService userService) {
super();
this.userService = userService;
}
public boolean isAuthenticUser(String userName, String password) {
// operation
}
}
In LoginServiceImpl
I'm not able to get the Servlet object.
I need it here so that I can use it for different purposes.
Any Idea?
解决方案 Finally I got a solution for it.
If someone wants to have access of the HttpServletrequest in the GWT-RPC service then the following can help.
Modify web.xml
<filter>
<filter-name>springRequestFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springRequestFilter</filter-name>
<url-pattern>/your_pattern/*</url-pattern>
</filter-mapping>
In Service
ServletRequestAttributes sra = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes());
sra.getRequest();
Hope this is helpful
这篇关于我如何在@service类中获得HttpServletRequestObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!