Hello,
I wrote the followint doFilter method:
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
if (filterConfig == null)
return;
HttpServletRequest request = (HttpServletRequest) arg0;
HttpServletResponse response = (HttpServletResponse) arg1;
String contentType = (String)
request.getAttribute("JPServletContentType");
if (contentType != null){
//response.setContentType(contentType);
}
String conType =
(String)filterConfig.getServletContext().getAttribute("JPServletContentType");
if (conType!=null) response.setContentType(conType);
String expires = (String) request.getAttribute("JPServletExpires");
if (expires != null)
response.setHeader("Expires", expires);
String cacheControl = (String)
request.getAttribute("JPServletCacheControl");
if (cacheControl != null)
response.setHeader("Cache-Control", cacheControl);
response.setContentType("text/plain");
long startTime = System.currentTimeMillis();
arg2.doFilter(request, response);
long stopTime = System.currentTimeMillis();
System.out.println("Time to execute request: " + (stopTime -
startTime) +
" milliseconds");
{
when i started the server, I saw a debug message :
2007-08-29 11:56:25,759 DEBUG [tomcat.localhost./servlet.Context]
Starting filter 'jpServletFilter'
But it doesn't seem to run the code, since I wrote the
System.out.print and id doesn't print to the log!
b
Manish Pandit - 30 Aug 2007 02:41 GMT
> Hello,
> I wrote the followint doFilter method:
[quoted text clipped - 7 lines]
>
> b
Did you put the 'Starting filter..' message in the init() method ? Can
you paste the init() body ? You are supposed to keep the filterConfig
that you get in the init() method. Apparently the line where you check
filterConfig == null is true, and the rest of the method does not
execute as the filter returns. Put a log.info or system.out.println
there to be sure.
-cheers,
Manish
odelya - 30 Aug 2007 08:06 GMT
> > Hello,
> > I wrote the followint doFilter method:
[quoted text clipped - 17 lines]
> -cheers,
> Manish
Hi,
I still have a problem:
I wrote in the jsp file:
<input name='JPServletContentType' type='hidden' value='text/plain'>
and in the filter:
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) {
....some code...
HttpServletRequest request = (HttpServletRequest) arg0;
HttpServletResponse response = (HttpServletResponse) arg1;
String contentType = (String)
request.getAttribute("JPServletContentType");
if (contentType != null) {
response.setContentType(contentType);
System.out.println(contentType);
} else
System.out.println("noContentType");
but the variable contentType returns null.
so i tried:
String conType = (String)
filterConfig.getServletContext().getAttribute("JPServletContentType");
if (conType != null)
{
response.setContentType(conType);
System.out.println(conType);
} else
System.out.println("noContentType2");
and still the conType returned null.
What's the way to get an attribut and send it?
Thank you!
Manish Pandit - 30 Aug 2007 18:09 GMT
> <input name='JPServletContentType' type='hidden' value='text/plain'>
> and in the filter:
> request.getAttribute("JPServletContentType");
JPServletContentType will come in as a request Parameter, not request
Attribute. That is why you're seeing a null. Why are you looking for
it in ServletContext ? If you feel you are unclear on the scopes
(request/context/session/page), attribute vs. parameters, read the
Sun's JSP/Servlet tutorial which can give you a nice overview.
Try request.getParameter("JPServletContentType") instead of
request.getAttribute(..) and you should see 'text/plain' as you set in
the JSP.
-cheers,
Manish
odelya - 02 Sep 2007 07:24 GMT
> > <input name='JPServletContentType' type='hidden' value='text/plain'>
> > and in the filter:
[quoted text clipped - 12 lines]
> -cheers,
> Manish
Hi,
I did it as you mentioned.
But it doesn't help, it still get the null.
Is there a way to get the whole html text that is sent to the server
and search in it for values?
Thank you!