我正在研究JSF(v1.2)应用程序.在我的应用程序中,我需要一个可以为任何资源(PDF,图像,Excel等)提供服务的通用servlet.我的想法是让调用者发送所需的信息,以便我可以使用一些配置找出正确的委托者类.
此委托者类将负责提供正确的资源.
例如,这是请求网址
http://example.com/servlet?delegatorid=abcd
Run Code Online (Sandbox Code Playgroud)
我的Servlet代码是这样的.
protected void doGet(HttpServletRequest request, HttpServletResponse response){
String delegatorID=request.getParameter("delegatorid");
//Get the configuration from Configuration table
configuration=getConfiguration(delegatorID);
//invoke the method of the delegator class based on this configuration
Object result=invokeMethod(configuration);
//write the response to the stream
}
Run Code Online (Sandbox Code Playgroud)
我的问题是在JSF项目中执行此操作的最佳方法是什么?
你能告诉我你对此的看法吗?
在FacesContext(和ExternalContext)只是一个门面了HttpServletRequest,HttpServletResponse,HttpSession,ServletContext与你不需要在所有在一个普通的servlet的一些具体JSF一起,etcetara.该ExternalContext#getSessionMap()无非是一个抽象的映射更多HttpSession#get/setAttribute().
在一个简单的vanilla servlet中,会话只能request.getSession()由getServletContext()通用方式和应用程序提供.另请参阅此相关问题:在任何与Servlet相关的类中按名称获取JSF托管bean.
您还可以将需要由JSF和Servlet共享的代码重构为一个实用程序方法,该方法没有任何依赖关系javax.faces.*或javax.servlet.*类(或最多只有javax.servlet.*),最后让调用者各自传递必要的信息.
| 归档时间: |
|
| 查看次数: |
5773 次 |
| 最近记录: |