简体   繁体   English

jsf托管bean的行为可以像servlet一样吗?

[英]Can a jsf managed bean behave like a servlet?

Normally, a servlet has doGet() and doPost() methods. 通常,servlet具有doGet()doPost()方法。 They are utilized to capture the incoming request parameters , which can then be used in any part of the application, if the developer wishes so. 它们被用于捕获传入的request parameters ,如果开发人员愿意,则可以在应用程序的任何部分中使用它们。

Now, If instead of using a servlet, a developer wishes to use a jsf managed bean , is there a way to get the request parameters in the bean itself ? 现在,如果开发人员希望使用jsf managed bean而不是使用servlet,是否有办法在bean本身中获取请求参数? If so , how can it be done ? 如果是这样,怎么办?

I have seen this POST which shows a way of getting stuff from request in JSF. 我看过这个POST ,它显示了一种从JSF的请求中获取内容的方法。 Can this be used to get a request parameter in managed bean like this : 这样可以用来在托管bean中获取请求参数吗?

HttpServletRequest origRequest = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
String myReqQuery1 = origRequest.getParameter("ReqQuery1");

In this case, will the application follow a jsf life cycle or a servlet life cycle or both ? 在这种情况下,应用程序将遵循jsf life cycle还是servlet life cycle或者同时遵循这两者?

JSF does not really work like that. JSF并不是真的那样工作。 The form fields in the view (.jsf or whatever) are mirrored by fields and properties in the bean. 视图中的表单字段(.jsf或其他内容)由Bean中的字段和属性进行镜像。 They are automatically populated by JSF when the servlet is invoked further up the stack. 当在栈中进一步调用servlet时,它们将由JSF自动填充。

This makes the need to read HTTP parameters redundant except when the browser lands on a JSF page from a non-JSF based form. 这使得需要读取HTTP参数是多余的,除非浏览器从非基于JSF的表单登陆到JSF页面上。 For that something like Spring-MVC can accept the URI being targetted and make a connection to the ManagedBean instance before redirecting the browser to a JSF powered URL. 为此,诸如Spring-MVC之类的东西可以接受目标URI,并在将浏览器重定向到JSF支持的URL之前建立与ManagedBean实例的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM