Sorry but i cannot follow you. I basically use the exact same code for my applet/jsp like you do with label printer. How did you manage to get the right session? Do i have to configure something? Here are the code i use for creating the applet, the applet itself and the jsp:
private void printPDFWithApplet(List <byte[]> list){
//UUID generieren und das PDF als Attribut in der Sitzung speichern
String uuid = UUID.randomUUID().toString();
HttpSession session = (HttpSession) Executions.getCurrent().getDesktop().getSession().getNativeSession();
session.setAttribute(uuid, list);
System.out.println("Session ist " + session);
//Button zum schließen des Applets
ToolBarButton link = new ToolBarButton();
link.setLabel("Click here to close this popup after printing is completed.");
link.addEventListener(Events.ON_CLICK, this);
appendChild(link);
//Neuer Div für das Applet
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.awt.print.PrinterJob;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.SimpleDoc;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.standard.DocumentName;
import javax.swing.JApplet;
import org.apache.commons.codec.binary.Base64;
public class MyApplet extends JApplet{
private static final long serialVersionUID = 1L;
private String key;
private int listSize = 0;
private List<byte[]> list;
public void init()
{
this.key = getParameter("key");
String s = getParameter("size");
try {
this.listSize = Integer.parseInt(s);
} catch (Exception e) {
System.out.println("Invalid listSize param=" + s);
this.listSize = 0;
}
this.list = new ArrayList();
for (int i = 0; i < this.listSize; i++)
{
String data = getParameter("data_" + i);
this.list.add(Base64.decodeBase64(data));
}
super.init();
showStatus("DAS APPLET IST JETZT INITIALISIERT!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
public void start()
{
System.out.println(getClass().getName() + " start()");
PrinterJob pjob = null;
PrintService service = null;
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
try
{
int count = 0;
do
{
URL url = new URL(getCodeBase(), "myapplet.jsp?key=" + this.key + "&count=" + (count + 1));
System.out.println("Protocol=" + url.getProtocol());
System.out.println("Host=" + url.getHost());
System.out.println("Port=" + url.getPort());
System.out.println("Default Port=" + url.getDefaultPort());
System.out.println("Path=" + url.getPath());
System.out.println("URL=" + url.toString());
URLConnection conn = url.openConnection();
int contentLength = conn.getContentLength();
System.out.println("ContentLength=" + contentLength);
InputStream is = conn.getInputStream();
System.out.println("InputStream=" + is.available());
byte[] data = (byte[])null;
if (contentLength != is.available())
{
data = (byte[])this.list.get(count);
System.out.println("list=" + data.length);
}
else
{
BufferedInputStream bis = new BufferedInputStream(is);
System.out.println("BufferedInputStream=" + bis.available());
ByteArrayOutputStream baos = new ByteArrayOutputStream(contentLength);
while (bis.available() > 0) {
baos.write(bis.read());
}
is.close();
bis.close();
data = baos.toByteArray();
baos.close();
System.out.println("ByteArrayOutputStream=" + data.length);
}
if ((data == null) || (data.length <= 0)) break;
count++;
if (pjob == null)
{
pjob = PrinterJob.getPrinterJob();
if (!pjob.printDialog()) break;
service = pjob.getPrintService();
}
DocPrintJob job = service.createPrintJob();
HashDocAttributeSet as = new HashDocAttributeSet();
as.add(new DocumentName("shipping label", null));
Doc doc = new SimpleDoc(data, flavor, as);
job.print(doc, null);
}
while (count < this.listSize);
showStatus(count + " label printed.");
} catch (Exception e) {
e.printStackTrace();
showStatus("Failed to print label - " + e.getLocalizedMessage());
}
}
public void destroy()
{
System.out.println(getClass().getName() + " destroy()");
}
public void stop()
{
System.out.println(getClass().getName() + " stop()");
}
}
<%@page import="java.io.BufferedOutputStream"%>
<%@page import="java.io.OutputStream"%>
<%@page import="java.util.Enumeration"%>
<%@page language="java" contentType="application/octet-stream"%>
<%
String key = request.getParameter("key");
if (key == null || key.trim().length() == 0 )
return;
Object object = session.getAttribute(key);
if (object != null && object instanceof java.util.List) {
java.util.List list = (java.util.List)object;
System.out.println("size=" + list.size());
if (!list.isEmpty()) {
byte[] data = (byte[])list.remove(0);
System.out.println("length=" + data.length);
response.setContentLength(data.length);
OutputStream os = response.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(data);
bos.flush();
} else {
response.setContentLength(0);
}
} else {
System.out.println("key not found=" + key);
response.setContentLength(0);
}
%>
I would really appreciate any help. The whole topic is totally new to me :(