Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

doubt in filters concept

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

/* this is my servlet program ****/

[ August 18, 2008: Message edited by: yuvraj kotegar ]
[ August 27, 2008: Message edited by: yuvraj kotegar ]
 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/***********this is my web.xml content**************/


/***** i have skipped the web-app tag**********/

[ August 18, 2008: Message edited by: yuvraj kotegar ]
[ August 27, 2008: Message edited by: yuvraj kotegar ]
 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package webcert.ch03.ex0304;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class MicroPaymentFilter implements Filter {

public void init(FilterConfig config) throws ServletException {
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

HttpServletRequestWrapper reqWrapper = new HttpServletRequestWrapper(
(HttpServletRequest) request);
String referrerName = reqWrapper.getPathInfo().substring(1);

if (referrerName != null) {
System.out.println("Micropayment made to " + referrerName);
reqWrapper.setAttribute("referrer", referrerName);
}
chain.doFilter(reqWrapper, response);
PrintWriter out = response.getWriter();
out.write("<BR >0.0001c has been paid to referrer " + referrerName</BR> ;
}

public void destroy() {
}

}


/??? this is my filter code???/
[ August 18, 2008: Message edited by: yuvraj kotegar ]
 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is i will be accessing the Micropayment servlet class from the URl i pass in request!!!

example

http://localhost:8080/ex0304/Micropayment/David

how will it access the filter class i wrote??
 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my doubt is how does the filter class i wrote get invoked ?? here in this case it is MicroPaymentFilter.

because in
MicroPaymentServlet class am not calling the filter class in anyway!!!
 
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on beginning Java.

For more information, please read this.

This post has been moved to a more appropriate forum.
 
Bear Bibeault
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Bear Bibeault
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by yuvraj kotegar:
my doubt is how does the filter class i wrote get invoked?

The container invokes the filter as configured in the deployment descriptor.

Perhaps this tutorial will help.
 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply

the response back to the client is given by my Filter class or the class i invoked??

like in this case is it MicroPaymentServlet or MicroPaymentFilter??
 
Bear Bibeault
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whichever writes to the response.

Please review proper use of the code tags.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic