spring和gwt整合,让gwt直接调用spring bean的前端servlet(三)

2014-11-24 08:29:22 · 作者: · 浏览: 2
printStackTrace();
}
return user;
}
});
System.out.println(userList);
String serverInfo = "";//getServletContext().getServerInfo();
String userAgent = "";//getThreadLocalRequest().getHeader("User-Agent");
// Escape data from the client to avoid cross-site script
// vulnerabilities.
input = escapeHtml(input);
userAgent = escapeHtml(userAgent);
return "Hello, " + input + "!

I am running " + serverInfo
+ ".

It looks like you are using:
" + userAgent;
}
/**
* Escape an html string. Escaping data received from the client helps to
* prevent cross-site script vulnerabilities.
*
* @param html
* the html string to escape
* @return the escaped string
*/
private String escapeHtml(String html) {
if (html == null) {
return null;
}
return html.replaceAll("&", "&").replaceAll("<", "<")
.replaceAll(">", ">");
}
}
5、然后在web.xml中配置第三步中定义的类即可,作为前端servlet总控制器,所有请求,都经过它来分发。
这样,gwt收到请求以后就直接委托给spring bean来处理了。
[html]
springGwtRemoteServiceServlet
com.vteba.test.rpc.SpringGwtRemoteServiceServlet
springGwtRemoteServiceServlet
/testgwt/*
6、也可以,每个RemoteServiceServlet都定义,然后配置在web.xml中,下面提供一个servlet基类,继承它后,spring bean可自动注入进来
[java]
public class AutowiredRemoteServiceServlet extends RemoteServiceServlet {
private static final long serialVersionUID = 1L;
public void init() throws ServletException {
super.init();
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
AutowireCapableBeanFactory factory = context.getAutowireCapableBeanFactory();
factory.autowireBean(this);
}
}
也可以将继承的RemoteServiceServlet换成HttpServlet,那么普通的servlet环境中,servlet也可以注入spring bean了。