You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Anthony W. Marino" <an...@AWMObjects.com> on 2001/05/05 01:23:32 UTC

ContentType is Always Null

(Redhat 7 with kernel 2.42; TomCat/ServletApi Build2001-05-04) - please note 
that I've tried this on TCb1 and TCb3 with the same results.

The following request url (as well as all other valid urls) always returns 
null for contentType:
   http://localhost:8080/xyz/servlet/ViewResource/index.html

******************* Some code within doGet method **********************

    // Get the resource to view
    URL url = null;
    try {
      url = getServletContext().getResource(req.getPathInfo());   
      return url;                  
    }
    catch (IOException e) {
      ....
      return;
    }
 
    // Connect to the resource
    URLConnection con = url.openConnection();
    con.connect();  
    // con.getURL() returns jndi:/localhost/xyz/index.html
 
    // Get and set the type of the resource
    String contentType = con.getContentType();  // This returns null
    res.setContentType(contentType);

***************************************************************************

Any suggestions?

Thank You,
Anthony

Re: ContentType is Always Null

Posted by "Anthony W. Marino" <an...@AWMObjects.com>.
I just commented out some code that snuck in during the email creation.

On Friday 04 May 2001 18:23, you wrote:
> (Redhat 7 with kernel 2.42; TomCat/ServletApi Build2001-05-04) - please
> note that I've tried this on TCb1 and TCb3 with the same results.
>
> The following request url (as well as all other valid urls) always returns
> null for contentType:
>    http://localhost:8080/xyz/servlet/ViewResource/index.html
>
> ******************* Some code within doGet method **********************
>
>     // Get the resource to view
>     URL url = null;
>     try {
>       url = getServletContext().getResource(req.getPathInfo());
>       // return url;
>     }
>     catch (IOException e) {
>       ....
>       return;
>     }
>
>     // Connect to the resource
>     URLConnection con = url.openConnection();
>     con.connect();
>     // con.getURL() returns jndi:/localhost/xyz/index.html
>
>     // Get and set the type of the resource
>     String contentType = con.getContentType();  // This returns null
>     res.setContentType(contentType);
>
> ***************************************************************************
>
> Any suggestions?
>
> Thank You,
> Anthony

Re: ContentType is Always Null

Posted by "Anthony W. Marino" <an...@AWMObjects.com>.
It's Tomcat 4.
On Friday 04 May 2001 18:23, you wrote:
> (Redhat 7 with kernel 2.42; TomCat/ServletApi Build2001-05-04) - please
> note that I've tried this on TCb1 and TCb3 with the same results.
>
> The following request url (as well as all other valid urls) always returns
> null for contentType:
>    http://localhost:8080/xyz/servlet/ViewResource/index.html
>
> ******************* Some code within doGet method **********************
>
>     // Get the resource to view
>     URL url = null;
>     try {
>       url = getServletContext().getResource(req.getPathInfo());
>       return url;
>     }
>     catch (IOException e) {
>       ....
>       return;
>     }
>
>     // Connect to the resource
>     URLConnection con = url.openConnection();
>     con.connect();
>     // con.getURL() returns jndi:/localhost/xyz/index.html
>
>     // Get and set the type of the resource
>     String contentType = con.getContentType();  // This returns null
>     res.setContentType(contentType);
>
> ***************************************************************************
>
> Any suggestions?
>
> Thank You,
> Anthony