Question: servlet filters

Ads

 
 
 

Share on Google+Share on Google+

venkatesh
servlet filters
1 Answer(s)      4 years and a month ago
Posted in : JSP-Servlet

Hi Any body please tell me how to work with servlet filters and can u post smple application to search webpage based on input values?

Ads
View Answers

April 10, 2013 at 3:42 PM


Hi venkatash,

In servlets the filters are used to develop the frientend controller design
patterns. It mean, wehenever we send
request to server with any  url, first
the request go through the fileter.
According the servlet specification
the filters are used for to store the
loggin information,for authentication
(checking get or post request),image
convertion , data compression etc. 
The filters contain the url like.

ex: authentication filers:

success.jsp:
 <html> 
  <body>
  we got success message
  </body>
 </html>

error.jsp:
----------
 get request is restricted.

 AuthenticationFilter.java:

 public class AuthentictionFilter implements Filter {

 public void init(FilterConfig config) {

  }

 public void doFilter(ServletRequest request,ServletResponse response,
                                                             FilterChain cahin) {
HttpServletRequest request1=(HttpServletRequest)request;
                  String method=request1.getMethod();

 if(method.equalsIgnoreCase("post")) {
                     chain.doFilter(request,response);
 }else {
  RequestDispatcher dis=request.getRequestDispatcher("error.jsp");
     dis.forward(request,response);
     }
   }

   public void destroy() {}
 }

 compile this one and palce in classes folder.

 web.xml:
    --------
 <web-app>
          <filter>
            <filter-name>af</filter-name>
            <filter-class>AuthenticationFilter</filter-class>
          </filter>

          <filter-mapping>
              <filter-name>af</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>
       </web-app>


 description:
    -------------
for filters no need to use <load-on-startup> tag. At time of
> deployment the server create the
> filter object and call the
> init(FilterConfig) method. whenever we
> send the request to server like
> http://localhost:8080/filterproject/success.jsp
> , first the server call the
> doFilter(ServletRequest,ServletResponse)
> method . This method check the request
> get or post. If the request mthod is
> get it forward the  request to
> error.jsp. If the request method id
> post the
> chain.doFilter(request,response) send
> the request to success.jsp.

Ads









Related Tutorials/Questions & Answers:
servlet filters
. According the servlet specification the filters are used for to store the loggin...servlet filters  Hi Any body please tell me how to work with servlet filters and can u post smple application to search webpage based on input values
Filters
Filters  Where we use Filters in the project? give one example code, how to use Filters to provide security for the application
Advertisements
filters in java - Struts
filters in java  I have implement Gzip filters in my web application, but web.xml is not supporting to filters in struts, i have implement the same code for servlet its working fine on local host but online web.xml is creating
Filters in Flex4
Filters in Flex4: Filters are used for effects not for style. You can use filters with MX and Spark components. You cannot apply them with style and setStyle() method. The package of filters is spark.filters.* and mx.filters.*. You
jQuery filters
jQuery filters       jQuery filters What is jQuery filters ? The jQuery filters... the power of selectors. Lets start with some basic filters for example
Use of jQuery attribute filters
Use of jQuery attribute filters       Use of jQuery attribute filters In this section you will learn how to use attribute filters of jQuery. Using jQuery attribute filters
struts2 filterdispatcher is deprecated please use the new filters
on starup: struts2 filterdispatcher is deprecated please use the new filters... <<< is deprecated! Please use the new filters
Design patterns interview questions2
to declaratively apply filters for intercepting requests and responses. For ex. Servlet filters. Q10. What is Front Controller pattern? Ans. It manages and handles requests through a centralized code. This could either be through a servlet
Servlet
Servlet  What is Servlet
Servlet
Servlet  how to navigate one servlet page to another servlet page
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  How many times the servlet is accessed
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
servlet
servlet  how to interact with a servlet from a swing program
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  i want to create a login page with servlet using database mysql? only in servlet not in jsp plzz help me out
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
Servlet
override Service method in the servlet when you extend GenericServlet to create servlet as it is mandatory to override it. But, when you extend HttpServlet to create a servlet then you can't override service method as there is a need to override
servlet
of the Servlet API. It contains the classes necessary for a standard, protocol-independent servlet. Every servlet must implement the Servlet interface in one
servlet
servlet  can i stoar record in variable which selected from table in servlet
servlet
servlet  dear sir servlet and html not run on eclips plz help me
servlet
servlet  how to create a login form using servlet using submit,edit delete button
servlet
servlet  i want a program for counting the no of times the servlet has been invoked
Servlet
Servlet  What must be implemented by all Servlets?    The Servlet Interface must be implemented by all servlets
Servlet
Servlet  I want to know the steps to write a simple servlet program... .   Hello Friend, Follow these steps: Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet. import java.io.*; import
servlet
servlet  how to read a file from different folder using filereader in servlet   Hello Friend, Please visit the following link: http://www.roseindia.net/servlets/servlet-read-file.shtml Here you will get an useful
servlet
servlet  i want to use servlet application on my web page then what should i do. I have already webspace.   Hi Friend, Please visit the following link: Servlet Tutorials Thanks
Servlet
Servlet   Why is Servlet so popular?   Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web
Tutorials   
Java Spring Hibernate Struts Training fat image from db fat image from db fat image from db fat image from db unable to get value returned from javascript variable in page How to change image size before adding to mysql using jsp Design a registration.jsp page with input for user registration details Cart Quantity jsp servlet coding issue servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? image pdf marking pdf marking Multiple image upload using JSP Read code from excel sheet and upload into database using JSP Student java about search engine Convert BLOB to PDF and save it to a location how to copy files from remote to local machine using SFTP SSL in java? Like Team viewer Socket and Servert -Jsp how to copy files from remote location to local using java? How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java how to create SOAP based web service in java? how to fetch data from mysql database table and draw a bar chart on that data using in jsp how to create users in LDAP using java? how to authenticate user using TIVOLI api in java? how to create users using IBM Tivoi API in jsp/servelet? Java/J2ee Please explain this code as many packages and classes are unknown to me .! how to download the uploaded folder files using jsp Login Query image is display from path of mysql database please reply the code to store dynamic fields in database? Reloading issue in jsp How to get Button Id ? calling one jap page from another jsp page login login Problem to get connection from DAO class to JDBC Page Loading Time Fix table's column's name row(1st row of the table) so that it does not move up when the table is scrolled up to view more rows below Sending hidden values

Ads

 
Advertisement null

Ads