applet调用jasperreport问题

cjbedu2012 2016-02-14 02:24:17
最近在使用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");
}
}
}
以下是错误提示
...全文
106 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
没睡醒的眼睛 2016-02-18
  • 打赏
  • 举报
回复
url = new URL("http://localhost:8080/Test/jasper/jasperReport/print.do"); 你检查一下这个URL在浏览器上面能否正常访问
cjbedu2012 2016-02-16
  • 打赏
  • 举报
回复
引用 2 楼 javasha 的回复:
需要设置Reponse的Content-type:"application/x-java-serialized-object"
设置了这个属性,还是报这个异常
没睡醒的眼睛 2016-02-16
  • 打赏
  • 举报
回复
需要设置Reponse的Content-type:"application/x-java-serialized-object"
cjbedu2012 2016-02-14
  • 打赏
  • 举报
回复
自己顶一个先

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧