wood burning stoves 2.0*
The moose likes Servlets and the fly likes Not getting control in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not getting control in Servlet" Watch "Not getting control in Servlet" New topic
Author

Not getting control in Servlet

Souvik Das
Greenhorn

Joined: Oct 11, 2007
Posts: 15
Hi All,
I am using ByteArrayInputStream for reading the content of one file and ServletOutputStream for writing the content in a web page. The code runs fine to upload the content in a web-page but the problem i am facing that i am not getting the control of the new webpage. I want to print the new webpage using javascript or java code.

I am using window.open() from the old page to open the new page.I have written all the code in the service method of a servlet to read the content from a file and to write the content in a new page.

Please guide me.


Thanks & Regards,
Souvik Das
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I have written all the code in the service method


Why in the service method? That is practically never necessary. The service method gets ALL HTTP requests, including HEAD, GET, POST, DELETE and PUT - surely you don't want all requests to get the same response.

Instead of jumping right in to coding your application you should study how other servlets are structured, starting with the very simplest. Surely the server you are working with came with simple examples.

Bill
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41129
    
  45
I don't understand what you mean by "the new web page". The code you showed streams bytes to the client (presumably binary?), so there will be no new web page, but a file that's sent to the browser.

I want to print the new webpage using javascript or java code.

Java code in the servlet can emit HTML and/or JavaScript for a web page, but JavaScript can not create a web page (not on the server, anyway).


Ping & DNS - my free Android networking tools app
Souvik Das
Greenhorn

Joined: Oct 11, 2007
Posts: 15
Hi Ulf Dittmer,
Yes you are right.It is not the new webpage. I have actually sent a file to the browser. What I want is to print that file which is being sent to browser. Actually, i am developing a search application where the user can print a number of files.
Does anyone know how to print that file which is sent to browser without asking user options for printing?

Please help.

Thanks in advance.
Souvik Das
Souvik Das
Greenhorn

Joined: Oct 11, 2007
Posts: 15
Hi William,
I have already gone through some examples of servlets but I have not got anything which can fulfill my purpose.

I just want to print the file which is already sent to browser without asking user options for print(Silent Print).

Can you help me resolving these issues?

Thanks & regards,
Souvik das
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41129
    
  45
I just want to print the file which is already sent to browser without asking user options for print(Silent Print).

That's not possible, and that's a very good thing. The user should be in control of a file he receives; he should choose whether to open it, save it, view it, print it or delete it.
Souvik Das
Greenhorn

Joined: Oct 11, 2007
Posts: 15
Hi Ulf Dimitter,
Actually our users do not want to control the file he receives. They want that the files get invoked and then get printed without asking them to print. Actuaaly it is very frustating for them to open a number of files and then manually fires command to print those files.

Can you give me any idea how I can solve this problem?
Thanks in advance,
Souvik Das
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

It doesn't matter whether your customers want it or not. Can't be done.

You'll have to look at some other technique. Perhaps a signed applet could do the trick? (Personally, not sure).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Hi Das,

What kind of files you want to show to the client? Is it multiple files to be shown simultaneously?

Ananth Chellathurai


Ananth Chellathurai [Walk on software]
Souvik Das
Greenhorn

Joined: Oct 11, 2007
Posts: 15
Hi Ananth,
In our application user serches for files based on different parameters and our application searches and shows the list of the files as search results. Then the user manually selects the files to be printed and then wants to print those files without asking them for print.

Now in my application the user only can open those files one by one. Rest of the application is to be developed.

Thanks in advance,
Souvik Das
Souvik Das
Greenhorn

Joined: Oct 11, 2007
Posts: 15
Hi Ananth,
In my application, all the files are pdf files. In one page i want to show multiple pdfs.

Thanks & regards,
Souvik Das
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41129
    
  45
All the browser PDF plugins I've encountered can only display a single PDF at a time. Which sort of makes sense, because an HTTP request can only return a single document, not several of them.
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Hi Das,

I have worked on a very similar kind of requirement. And we found no solutions to open more pdfs on a single click. Then we designed to show the content of the pdf in browser itself instead of opening it with Acrobat or any PDF viewer.

We used PDFBox-0.7.3 API to get the content of the pdf using PDFTextStripper class and displayed it to the browser, however the formatting of the document has gone. Let us see what others suggest for this.

Ananth Chellathurai
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Sounds like a job for Java Server Faces style application to me.
Bill
Souvik Das
Greenhorn

Joined: Oct 11, 2007
Posts: 15
Hi Ulf Dittmer,
Can it be possible that we merge all the pdfs at runtime(in the servlet) and then send the pdf to the browser(client)?

Thanks & Regards,
Souvik Das
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41129
    
  45
Can it be possible that we merge all the pdfs at runtime(in the servlet) and then send the pdf to the browser(client)?


Yes, that's possible. The iText web site has examples that show how to do that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not getting control in Servlet
 
Similar Threads
Streaming out data using ServletOutputStream
Displaying file content in a jsp page
Excel file - download
How to Return Javascript Alert
Servlet downloads Excel file ok but also attempts Servlet & JSP files !!