Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

A cloven question:Servlet dual output  RSS feed

 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
Hopefully I can ask a two topic question:
1. Dual file output from Servlet
I can successfully send a file to the browser. I also want to create a copy locally. After getting ArrayIndex errors I thought I was very clever and cloned the byte array. I am still getting errors. Can this be done?

byte[] buf = new byte[1024];
byte[] buf2 = new byte[1024];
int len;
while((len = input.read(buf)) > 0)
//System.arraycopy(buf,0,buf2,0,buf.length); //even when I use len
//copyTo.write(buf2, 0, len);
stream.write(buf, 0, len); //this is going to the browser

This works as is. When I uncomment the two lines, everything fails w/Index error. How/Can I write a file to the browser and locally within the while loop?

2. jsp lugin
I have a context "demo" with a class, "demoApplet", in a package AppletDemo and I am unclear/unable to configure the jsp lugin. I can do the following, which doesnt work, grin.
<jsp lugin type="applet" code="demoApplet.class" codebase="http://localhost:8083/demo/WEB-INF/class/AppletDemo" jreversion="1.4.2"> </jsp lugin>
What is the minimal correct config necessary to launch the applet? tia.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"cp cp",
please read (or at least browse) the JavaRanch display name rule here.

Disply names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and fix your display name. Accounts with invalid display names get deleted, often without warning

thanks,
Dave.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With respect to your first question (and it is better to ask question in separate threads in future please) there is a JSP tag library that can duplicate the output in the way you want.

For your second question, applications are not allowed to directly serve files from the WEB-INF directory. You'll need to JAR them up and place them a level higher.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the code from the first part of your question a direct cut-and-paste?
If so, you just learnt an importent lesson: always use brackets, even when they (currently) only have a single line. Always always always.




[Edit - oops, error with code tags]
[ September 06, 2005: Message edited by: David O'Meara ]
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David
Thanks. I have amended my ways, requesting the indulgence to finish this dual thread.
1. What is the jsp tag library that will duplicate the file and how woudl I use it from within a servlet?
2. How/would I place the jar w/the demoApplet class outside of the WEB-INF and would I just refer to it as /context/demoApplet.jar?
Originally posted by David O'Meara:
With respect to your first question (and it is better to ask question in separate threads in future please) there is a JSP tag library that can duplicate the output in the way you want.

For your second question, applications are not allowed to directly serve files from the WEB-INF directory. You'll need to JAR them up and place them a level higher.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. I can't remember :roll: If this was a separate thread I could send it to JSP and someone there could tell you.

2. Yep, place in the context root, refer to it as http://.../demo/myDemo.jar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!