aspose file tools*
The moose likes Servlets and the fly likes doubt in filters concept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "doubt in filters concept" Watch "doubt in filters concept" New topic
Author

doubt in filters concept

yuvraj kotegar
Ranch Hand

Joined: Jul 31, 2008
Posts: 120

/* 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

Joined: Jul 31, 2008
Posts: 120
/***********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

Joined: Jul 31, 2008
Posts: 120
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

Joined: Jul 31, 2008
Posts: 120
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

Joined: Jul 31, 2008
Posts: 120
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!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61656
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61656
    
  67

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61656
    
  67

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

Joined: Jul 31, 2008
Posts: 120
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61656
    
  67

Whichever writes to the response.

Please review proper use of the code tags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in filters concept