Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in filters concept

 
yuvraj kotegar
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!!!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whichever writes to the response.

Please review proper use of the code tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic