• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not getting control in Servlet

 
Souvik Das
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Souvik Das
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Das,

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

Ananth Chellathurai
 
Souvik Das
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a job for Java Server Faces style application to me.
Bill
 
Souvik Das
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic