Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

open word from a servlet

 
Per Lovdinger
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is the scenario:
- the user submits a form and activate a servlet
- the servlet writes a file ( a word document) to disk
- now I want the servlet to open the word document....
How do I do that ?
- I've tried with a forward request, but that only displays the content in the browser, I want to open the document in word.
thanks in advance
....Per
 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Check out if this is what u wanted.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.*;
public class postRecieved extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("application/msword");
PrintWriter pw=res.getWriter();
pw.println("Sandy how are u doing ");
pw.close();
}
}

------------------
Try and Try Till u succeed
Sandeep Jain
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic