wood burning stoves 2.0*
The moose likes Servlets and the fly likes Need suggestion regarding an issue related to content type header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need suggestion regarding an issue related to content type header" Watch "Need suggestion regarding an issue related to content type header" New topic
Author

Need suggestion regarding an issue related to content type header

Abhishek Purwar
Ranch Hand

Joined: Dec 15, 2007
Posts: 63

Hi All,

I have web application and I prepare war file for deployment. Classes are put inside {location}/WEB-INF/classes location and static contents like images, javascript files, static jsps, etc. are put at following location {location}/resources/.
When I tried to access static resources from browser (url : http://{domain name}/resource/{resource name}), no filter of web app is called. Even filter which is set for every request is not getting called. Can anybody provide some suggestion on this?
And one more thing, if I want to set content type in response header for static resource then how can I set that?

I need help on this.Please provide your views on this.

Thanks to all in advance for their suggestions.


Abhishek Purwar,
Bangalore.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

What filter mappings have you setup?

As for the content types for static resources, as far as I know these can only be setup in the web.xml file, in a mime-mapping element.

I'll move this thread to our Servlets forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhishek Purwar
Ranch Hand

Joined: Dec 15, 2007
Posts: 63

Thanks for your reply Rob.

Following are the filter mapping which I set up:

<filter>
<filter-name>{filter name 1}</filter-name>
<filter-class>{Class name}</filter-class>
</filter>
<filter-mapping>
<filter-name>{filter name 1}</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>{filter name 2}</filter-name>
<filter-class>{Class name}</filter-class>
</filter>
<filter-mapping>
<filter-name>{filter name 2}</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

For static resource, none of this get called.

And I set the mime-mapping in web.xml but nothing happens. (.png file get parsed by browser and shows character stream in browser instead of image, .ico file same as .png and for some other types of file also.) Following is mime-mapping which I setup in web.xml file :

<mime-mapping>
<extension>png</extension>
<mime-type>image/x-png</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>

And I am using weblogic server for my application and environment is linux.

Please provide some suggestion for this.
Sujata Samal
Greenhorn

Joined: Jan 29, 2008
Posts: 20
Hi Abhishek,

Try * inplace of /* in <url-pattern>/*</url-pattern> tag to map all requests if you have only one application deployed.

-Sujata
Abhishek Purwar
Ranch Hand

Joined: Dec 15, 2007
Posts: 63

Filter mapping issue is fixed and now filter is getting called for every request.

Any suggestion for content type issue??
Sujata Samal
Greenhorn

Joined: Jan 29, 2008
Posts: 20
Have you tried setting the contectType in response object something like - response.setContentType("image/png") ??

-Sujata
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

There is no response for static images, only in servlets and JSP pages. That's the whole issue.
Abhishek Purwar
Ranch Hand

Joined: Dec 15, 2007
Posts: 63

Thanks for your responses.

@Sujata : I need to set content type for all static resources at common place and not in some class file.

@Rob: Actually, mime-mapping I setup at wrong place in web.xml file. Now I place it just befoe welcome-file-list tag and it is working now.

Issue is resolved.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need suggestion regarding an issue related to content type header
 
Similar Threads
Error 500: Filter [Spring OpenEntityManagerInViewFilter]: could not be loaded
Do I have to choose only one view solution in Struts2?
Need suggestion regarding an issue related to content type header
Need suggestion
Need suggestion regarding an issue related to content type header