Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2004

Tip: Looking for answers? Try searching our database.

custom tags and content type

Thread view: 
luca passani - 05 Mar 2004 20:09 GMT
here's my big problem today. I am creating a tag-lib and I need the top tag to
take care of setting the content type. My tag goes like:

public int doStartTag() throws JspException {

 try {
   HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();

   HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();

   response.setContentType("text/vnd.wap.wml");

   :
 }

My JSP file looks like:

<%@ taglib uri="/WEB-INF/tld/tags.tld" prefix="pref" %><pref:document>

(i.e. evrything squeezed on the very first line
to make sure that no char escapes and the default text/html content type
is not generated).
Alas. It doesn't work. I keep getting text/html.

I made some tests and if I set the mime type explicitly in the JSP like below
(after removing the contenttype() line from the taglib) it works!

<%
response.setContentType("text/vnd.wap.wml");
%><%@ taglib uri="/WEB-INF/tld/tags.tld" prefix="pref" %><pref:document>

any idea?

thanks

luca
Tor Iver Wilhelmsen - 05 Mar 2004 21:17 GMT
> any idea?

You can set the content type in a @page directive, if that helps.
luca - 06 Mar 2004 01:39 GMT
>>any idea?
>
> You can set the content type in a @page directive, if that helps.

unfortunately, it doesn't. The mime-type I send is conditional.
It could be text/html or text/vnd.wap.wml

the tag has the logic to decide which....

luca
William Brogden - 06 Mar 2004 13:59 GMT
> here's my big problem today. I am creating a tag-lib and I need the top tag to
> take care of setting the content type. My tag goes like:
[quoted text clipped - 28 lines]
>
> any idea?

Most people would handle this situation by having a front end servlet
decide what response type is needed and forwarding to the correct
JSP.  I suspect that the behavior you want to use - of not setting the
response type until the first char is sent - is not a standard and may
change between servlet engines.

Bill


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.