• Post Reply Bookmark Topic Watch Topic
  • New Topic

WebLogic - Viewing a file sent by a servlet

 
Javier Calvo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
I've a little problem... First of all I'm using:
- Weblogic 6.1
- Internet Explorer 5
- JDK 1.3.1
I'm using a servlet to download a file as a byte[]. This works fine. Now I'm trying to use this same servlet to dl the same file but the client side opens it in the browser.

The code for this servlet:
ServletOutputStream out = response.getOutputStream();
ServletContext ctx = this.getServletConfig().getServletContext();
String contentType =ctx.getMimeType(file);
String disposition = "inline";
if (contentType == null || contentType.length()==0){
contentType ="application/octet-stream";
disposition = "attachment";
}
response.setContentType(contentType);
response.setContentLength(fileByte.length);
response.setHeader("Content-disposition", disposition+"; filename=\""+file+"\"");
out.write(fileByte);
out.flush();
out.close();

I've defined some MIME Types in the web.xml and the servlet can find them.
But this doesn't work fine:
-for "txt" files, it opens it in the browser ---> OK
-for "bmp" files, it ask me to choose between "open it" or "download it" ---> OK the Internet Explorer 5 doesn't recognize the bmp format.
-for "doc" file, that's my problem. I have a server error:
<HTTP> <HttpServer(1297127,null default ctx,myserver) found no context for "/_vti_inf.html". This request does not match the context path for any installed web applications and there is no default web application configured

Well, if i put "attachment" instead of "inline", it ask me to "open it" or to "save it" and if I open it, it works.
The MIME type is "application/msword".
So I'm a bit confused.
Does anyone have an idea??
Thx
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused (not an unusual state :roll: )
You are trying to open an MSWord file, but you DON'T want to open it in MSWord? You want your Browser to be able to handle the MSWord formatting correctly and display it inline? Is that what I am seeing?
This could be a problem . . . . sort of MicroSofts nefarious way of continuing to sell zillions of licenses for MSWord .
 
Javier Calvo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact I want to see the doc in the browser like this link:
http://www.sharemation.com/~gmgershon/Word%20MIME%20Word.doc
or if someone has another idea to open a doc without saving it in a file ?
[ April 23, 2003: Message edited by: Javier Calvo ]
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The context.getMimeType(String file) method is giving you a null, meaning the MIME type is not known.
The MIME type depends on the configuration of the servlet container, and may be specified in a web application deployment descriptor.
Try this in your web.xml:
<mime-mapping>
<extension>doc</extension>
<mime-type>application/msword</mime-type>
</mime-mapping>
HTH
 
Javier Calvo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have describe the MIME type in the web.xml and I printed it to the screen and it was correct so it find it.
All does work if I give the doc file in attachment but what I want is to open it without asking the user to click on the "open" button...
 
Javier Calvo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx a lot for your help...
I resolve my problem by installing the Service Pack 4 of WebLogic...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!