problem in using <t:inputFileUpload> - java

I have followed this tutorial from BalusC for FileUpload. but setter isn't getting called

That can have the following causes:
The enctype="multipart/form-data" attribute is missing on the <h:form>. This is mandatory in order to be able to send files to the server.
The ExtensionsFilter is missing in web.xml or not properly mapped on the servlet name of the FacesServlet. This is mandatory in order to be able to parse the multipart/form-data request.
There is another filter in the request-response chain before the ExtensionsFilter which has already parsed the multipart/form-data request beforehand. For example, when you're using RichFaces4, such a filter will be auto-loaded without that you need to declare it in web.xml. Request bodies can be parsed only once, so the ExtensionsFilter would receive an empty request after such another filter.
There is another filter in the request-response chain before the ExtensionsFilter which has completely skipped the ExtensionsFilter by for example forwarding or redirecting the request.

Related

Why write a servlet filter for a DispatcherType other than REQUEST?

I've seen plenty of servlet filters in my time for doing all kinds of things but always on REQUEST never anything else. Does anyone have any use cases or examples of why it might be useful to write a servlet filter for another dispatcherType, other than REQUEST?
The DispatcherTypes as in javax.servlet package.
public enum DispatcherType {
FORWARD, INCLUDE, REQUEST, ASYNC, ERROR
}
Well the names are rather self-explaining. The REQUEST is indeed the most often used one and it's applied on the incoming request chain. Here is when you may need to use the others (because the REQUEST only dispatched filters will not be applied):
FORWARD - if you want to filter request/response when one servlet forwards the request to another servlet. Often this is used when a servlet forwards to a JSP page.
INCLUDE - if you want to filter request/response when one servlet calls another servlet in order to include it's response in the own response. Often this is used when a JSP page includes JSP page.
ASYNC - This is something I personally never used but AFAIK it's needed to be able to filter the asynchronous requests introduced in Servlet 3 spec
ERROR - if you want to filter request/response when the servlet call results in error.
See https://sling.apache.org/documentation/the-sling-engine/filters.html#filter-chains for some more details.

Using original URL request for proxied HttpServlet Request

I have an Apache proxy which redirects requests to /foo/bar to a web app running on /foo. The problem is that I have a Servlet filter in my filter chain which requires the request to still be in the /foo/bar format. It is an authentication filter I can't change and this is resulting in incorrect redirects after login to /foo instead of /foo/bar.
Following other similar threads, I've attempted using RequestDispatcher.forward with a modified request and HttpServletResponse.sendRedirect to modify the URL. The first approach seems to skip the rest of my filter chain, and the second goes to the proxy which then modifies the URL back to /foo.
Is there any way around this. Ideally what I'd like is for just the authentication filter to get a /foo/bar request and the rest of the chain to get a /foo request.
Looks like HttpServletRequestWrapper was what I was looking for. Just needed to extend this and provide getRequestURI and getRequestURL overrides (rather like described here). Then needed to add filter mappings before and after my auth filter to convert the request URL/URI as needed.

How servlet handle multiple request from same jsp page

Sorry friends if this question is very easy but i am confuse i unable to find out solution.
As we all know in spring MVC framework we create controller which will handle multiple request from same page using #requestmapping annotation.
but same thing i want to do in servlet how can i do ?
Suppose i have a jsp which which will contain a jqgrid,and two forms i want to use only one servlet to load the data into jqgrid and that servlet only will handle request from both the form . Since we have only doGet and doPost in servlet how one servlet fulfill all three request. Hope you understand my question if you have and link where i get sample or and tutorial link plz reply me
Well, the only easy way to do this would be to use a request parameter to control how the processing happens.
In a very basic example, you may have something like a requestType value that gets passed as either part of the query string or the request body. You would assign values of 1-3 (or 0-2) with each value indicating a different type of request. Your servlet would then parse the request accordingly.
This actually is how the DispatcherServlet in SpringMVC works. There's only one servlet class instance and when a request comes in, it examines the query string along with other parts of the request to determine which controller should handle the request.

Guice servlet DSL, filter all but one URL

I want to filter all requests to my web application through my "SecurityFilter" which checks that a session variable "authToken" is valid. The problem is that in order to get this token you need to hit the "AuthServlet" which is at /auth.
I need to filter all servlets except the /auth servlet with my "SecurityFilter". How can I do this via guice-servlet?
I thought of trying to no avail...
filterRegex("!((.)*auth(.)*)").through(PortSecurityFilter.class);
^((?!/authorize).)*$ worked.

JSF Servlet Arch Help needed

i want a mechanism in my web app as described below:
user will enter mydomain.com/CompanyName , depending upon the CompanyNameit will show its logo and its customized page, and i will take that parsed parameter in session again upon each request i will compare the parsed CompanyName and one stored in session , and if they matched then application will show the requested page with user's data.else it will be redirected to login page.
and the main thing is i want this thing in JSF arch.
i tried taking a servlet that will resolve all request and it will parse and then will dispatch the request to prefered servlet,but problem is it goes in loop as again it resolves to the same controller servlet,
You can do this via a phase listener. You can define a global one in faces-config.xml (or using annotations, if JSF 2.0 is used)
<lifecycle>
<phase-listener>com.yourcompany.CompanyPhaseListener</phase-listener>
</lifecycle>
There you have access to the FacesContext, from which you can obtain the current request URI. Parse it and store the appropriate attributes in the request, which you can later read on your pages.
The phase listener is executed on the specified phase(s), and perhaps you should choose RENDER_RESPONSE
For affecting the way your URLs appear in the browser, check PrettyFaces.
i tried taking a servlet that will resolve all request and it will parse and then will dispatch the request to prefered servlet,but problem is it goes in loop as again it resolves to the same controller servlet,
Use a Filter instead. It by default doesn't listen on forwarded requests, so you won't get an infinite loop on forwarding.

Categories