Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need suggestion regarding an issue related to content type header

 
Abhishek Purwar
Ranch Hand
Posts: 63
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhishek Purwar
Ranch Hand
Posts: 63
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Filter mapping issue is fixed and now filter is getting called for every request.

Any suggestion for content type issue??
 
Sujata Samal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried setting the contectType in response object something like - response.setContentType("image/png") ??

-Sujata
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no response for static images, only in servlets and JSP pages. That's the whole issue.
 
Abhishek Purwar
Ranch Hand
Posts: 63
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic