You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Chris Searle <ne...@chrissearle.org> on 2005/05/06 16:16:03 UTC
VelocityViewServlet and mime-mapping in web.xml
Was reading thru the list/google - since we needed a non-singleton
version of VVS. So - the following is using Velocity tools from
subversion as of today 6. may.
While reading I found some articles where it suggested to use
mime-mappings instead of overriding the VelocityViewServlet for each
mime-type and overriding the setContentType method for each. Makes
sense to me - three servlets -> one.
Have the following sections in web.xml:
<servlet>
<servlet-name>VelocityView</servlet-name>
<display-name>VelocityView</display-name>
<servlet-class>no.empolis.servlet.VelocityView</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>VelocityView</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>VelocityView</servlet-name>
<url-pattern>*.txt</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>VelocityView</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>.txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<mime-mapping>
<extension>.css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>.vm</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
Note - the custom servlet VelocityView simply overrides the doRequest
method - looks at the IP address of the request and sets a value in
the http session object then calls super.doRequest() - nothing about
Content Type. One particular internal machine needs a different view
than all the others :)
Now - without the mime-mapping section - any .vm files are returned as
text/plain (they are normally called via the struts servlet
framework). With the mime-mapping section - the .vm files are returned
as text/html - and therefore render in the browser.
However - the css files (which are called directly - not thru the
struts framework) also return as text/html - not text/css. The content
is correctly parsed by velocity - it's just the content type that is
wrong.
What have I misunderstood here - is this not the correct way to use
the mime-mappings settings? Should this work with VVS?
--
Chris Searle
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: VelocityViewServlet and mime-mapping in web.xml
Posted by Nathan Bubna <nb...@gmail.com>.
i've never used the web.xml mime-setting stuff much and don't know
much about it. i suggest you try to override the setContentType
method in your subclass to set the file type according to the
requested file's extension.
On 5/6/05, Chris Searle <ne...@chrissearle.org> wrote:
>
> Was reading thru the list/google - since we needed a non-singleton
> version of VVS. So - the following is using Velocity tools from
> subversion as of today 6. may.
>
> While reading I found some articles where it suggested to use
> mime-mappings instead of overriding the VelocityViewServlet for each
> mime-type and overriding the setContentType method for each. Makes
> sense to me - three servlets -> one.
>
> Have the following sections in web.xml:
>
> <servlet>
> <servlet-name>VelocityView</servlet-name>
> <display-name>VelocityView</display-name>
> <servlet-class>no.empolis.servlet.VelocityView</servlet-class>
>
> <load-on-startup>2</load-on-startup>
>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>VelocityView</servlet-name>
> <url-pattern>*.vm</url-pattern>
> </servlet-mapping>
> <servlet-mapping>
> <servlet-name>VelocityView</servlet-name>
> <url-pattern>*.txt</url-pattern>
> </servlet-mapping>
> <servlet-mapping>
> <servlet-name>VelocityView</servlet-name>
> <url-pattern>*.css</url-pattern>
> </servlet-mapping>
>
> <mime-mapping>
> <extension>.txt</extension>
> <mime-type>text/plain</mime-type>
> </mime-mapping>
> <mime-mapping>
> <extension>.css</extension>
> <mime-type>text/css</mime-type>
> </mime-mapping>
> <mime-mapping>
> <extension>.vm</extension>
> <mime-type>text/html</mime-type>
> </mime-mapping>
>
> Note - the custom servlet VelocityView simply overrides the doRequest
> method - looks at the IP address of the request and sets a value in
> the http session object then calls super.doRequest() - nothing about
> Content Type. One particular internal machine needs a different view
> than all the others :)
>
> Now - without the mime-mapping section - any .vm files are returned as
> text/plain (they are normally called via the struts servlet
> framework). With the mime-mapping section - the .vm files are returned
> as text/html - and therefore render in the browser.
>
> However - the css files (which are called directly - not thru the
> struts framework) also return as text/html - not text/css. The content
> is correctly parsed by velocity - it's just the content type that is
> wrong.
>
> What have I misunderstood here - is this not the correct way to use
> the mime-mappings settings? Should this work with VVS?
>
> --
> Chris Searle
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org