最近在使用applet调用jasperreport时遇到了个问题,求解
1、springmvc的action
@Controller
@RequestMapping(value="
/jasper")
public class JasperControler
{
@RequestMapping(value="
/jasperReport/print")
public String print(HttpServletRequest request,HttpServletResponse response,Model model) throws Exception
{
//省略一部分
ServletOutputStream ouputStream = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
oos.writeObject(jasperPrint);
oos.flush();
oos.close();
return null;
}
2、applet出错的语句
public class FirstPrint extends JApplet
{
private static final long serialVersionUID = 7287295574566683047L;
private URL url = null;
private JasperPrint jasperPrint = null;
private String flag; //判断打印还是打印预览,0表示打印,1表示打印预览
public void init(){
//String strUrl = getParameter("REPORT_URL");
String strUrl = "http://localhost:8080/Test/jasper/jasperReport/print.do";
flag = getParameter("REPORT_FLAG");
if (strUrl != null){
try{
// url = new URL(getCodeBase(), strUrl);
url = new URL("http://localhost:8080/Test/jasper/jasperReport/print.do");
}catch (Exception e){
StringWriter swriter = new StringWriter();
PrintWriter pwriter = new PrintWriter(swriter);
e.printStackTrace(pwriter);
JOptionPane.showMessageDialog(this, swriter.toString());
}
}else{
JOptionPane.showMessageDialog(this, "init():Source URL not specified");
}
}
public void start() {
if (url != null){
if (jasperPrint == null){
try{
System.out.println("开始获取报表数据");
jasperPrint = (JasperPrint)JRLoader.loadObject(url); //
此处获取的值是空的
System.out.println("完成获取报表数据");
}catch (Exception e){
StringWriter swriter = new StringWriter();
PrintWriter pwriter = new PrintWriter(swriter);
e.printStackTrace(pwriter);
JOptionPane.showMessageDialog(this, swriter.toString());
}
}
if (jasperPrint != null){
final JasperPrint print = jasperPrint;
if(flag.equals("0")){
Thread thread = new Thread
(
new Runnable(){
public void run(){
try{
///////
}catch (Exception e){
StringWriter swriter = new StringWriter();
PrintWriter pwriter = new PrintWriter(swriter);
e.printStackTrace(pwriter);
System.out.println(e.toString());
JOptionPane.showMessageDialog(null, swriter.toString());
}
}
}
);
thread.start();
}else{
try {
JRViewer view =new JRViewer(print);
this.getContentPane().add(view);
view.setVisible(true);
view.requestFocus();
this.setVisible(true);
view.setFocusable(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}else{
JOptionPane.showMessageDialog(this, "Empty report.");
}
}else{
JOptionPane.showMessageDialog(this, "start():Source URL not specified");
}
}
}
以下是错误提示