HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: junit/framework/Test解决方法
package webViewer; import java.io.*; import junit.framework.Test; import com.aspose.words.*; //引入espouse-word-14.11.0-jdk16.jar包 public class Word2Pdf {
private static boolean getLicense() {
boolean result = false;
try {
InputStream is = Test.class.getClassLoader().getResourceAsStream("wordlicense.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下
com.aspose.words.License aposeLic = new com.aspose.words.License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
} public static void word2pdf(String Address) { if (!getLicense()) { // 验证License 若不验证则转化出的PDP文档会有水印产生
return;
}
try {
File file = new File("C:/inetpub/wwwroot/web/file/pdf1xxxx.pdf"); //新建一个空白pdf文档
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document(Address); //Address是将要被转化的word文档
doc.save(os, SaveFormat.PDF); //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
运行代码
package webViewer;
public class Test {
public static void main(String[] args){
Word2Pdf.word2pdf("http://172.16.8.80/file/4.docx");
/*File f=new File("C:/Program Files (x86)/Apache Software Foundation/Tomcat 7.0/webapps/generic/web/file/pdf1.pdf");
if(f.exists()){
f.delete();
} else{
System.out.println("无文件");
}*/
}
}
运行以上代码可以正常生成想要的pdf文件
但是将java函数放到jsp中
如下
<%@ page language="java" import="java.sql.*" import="java.util.*" import="java.io.*" pageEncoding="utf-8" %>
<%@ page import="webViewer.*" %>
<%@ page import="com.aspose.words.*" %>
<%@ page import="com.aspose.cells.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'View.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head>
<%
String pdfFileAddress=request.getParameter("pdfFileAddress");
String suffix=request.getParameter("suffix");
String pdfFileAddress1;
%>
<body>
<%
/* File f=new File("C:/Program Files (x86)/Apache Software Foundation/Tomcat 7.0/webapps/generic/web/file/pdf1.pdf");
if(f.exists()){
f.delete(); }
else{ */
%>
<%
if(suffix.equals("doc")||suffix.equals("docx")){
Word2Pdf.word2pdf("http://172.16.8.80/"+pdfFileAddress); // Word2Pdf.word2pdf("http://172.16.8.80/file/4.docx");
/* Word2Pdf.word2pdf("http://172.16.8.80/"+pdfFileAddress);*/
/* try {
File file = new File("C:/Program Files (x86)/Apache Software Foundation/Tomcat 7.0/webapps/generic/web/file/pdf1.pdf");
FileOutputStream os = new FileOutputStream(file);
Document doc = new Document("C:/Program Files (x86)/Apache Software Foundation/Tomcat 7.0/webapps/generic/web/"+pdfFileAddress);
doc.save(os, com.aspose.words.SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
os.close();
} catch (Exception e) {
e.printStackTrace();
} */
pdfFileAddress1="file/pdf1xxxx.pdf";
}else{
if(suffix.equals("xls")||suffix.equals("xlsx")){
Excel2Pdf.excel2pdf("http://172.16.8.80/"+pdfFileAddress);
pdfFileAddress1="file/pdf1yyyy.pdf";
}/*else{
if(suffix.equals("ppt")||suffix.equals("pptx")){
Ppt2pdf.ppt2pdf("http://172.16.8.80:8080/generic/web/"+pdfFileAddress);
pdfFileAddress1="file/pdf1.pdf";
}*/ else{
pdfFileAddress1=pdfFileAddress;
}
}
/*}*/ %>
<iframe src="http://172.16.8.80/viewer.html?file=<%=pdfFileAddress1%>" height="600px" width="680px"></iframe>
</body>
</html>
页面会出现以下错误
HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError:
junit/framework/Test
type Exception report
message javax.servlet.ServletException: java.lang.NoClassDefFoundError:
junit/framework/Test
description The server encountered an internal error that prevented it from fulfilling
this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException:
java.lang.NoClassDefFoundError: junit/framework/Test
org.apache.jasper.servlet.JspServletWrapper.handleJspException
(JspServletWrapper.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:462)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.servlet.ServletException: java.lang.NoClassDefFoundError: junit/framework/Test
org.apache.jasper.runtime.PageContextImpl.doHandlePageException
(PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException
(PageContextImpl.java:845)
org.apache.jsp.View_jsp._jspService(View_jsp.java:179)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NoClassDefFoundError: junit/framework/Test
webViewer.Word2Pdf.getLicense(Word2Pdf.java:13)
webViewer.Word2Pdf.word2pdf(Word2Pdf.java:25)
org.apache.jsp.View_jsp._jspService(View_jsp.java:133)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.70
logs.
Apache Tomcat/7.0.70
经上网研究,解决方法是:tomcat的lib库中缺少junit.jar包
涨到Eclipse中junit.jar包 如图:
将该jar包拷贝到tomcat的lib目录中 如下图
最后重新启动tomcat即可正常生成pdf。
HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: junit/framework/Test解决方法的更多相关文章
- HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag
我在项目中导入了jar,还是不能使用EL表达式,一运行就出现了下面的额错误: org.apache.jasper.JasperException: javax.servlet.ServletExcep ...
- javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver错误解决办法
今天不用eclipse.myeclipse等开发工具,纯手写JSP页面(有点作死)时突然出现以前从来没遇到过的问题,报错如下: HTTP Status 500 - java.lang.NoClassD ...
- 关于jsp web项目中的javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver错误
错误: javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver org.apache.j ...
- idea调试SpringMvc, 出现:”javax.servlet.ServletException: java.lang.IllegalStateException: Cannot create a session after the response has been committed"错误的解决方法
调试拦截器出现以下错误: HTTP Status 500 - javax.servlet.ServletException: java.lang.IllegalStateException: Cann ...
- HTTP Status 500 - javax.servlet.ServletException
运行某个jsp页面时提示 type Exception report message javax.servlet.ServletException: java.lang.NoClassDefFound ...
- javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation:
javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving ...
- 类似java.lang.NoClassDefFoundError: org/jaxen/JaxenException解决方法
在使用dom4j的xpath时出现java.lang.NoClassDefFoundError: org/jaxen/JaxenException的异常,原因是dom4j引用了jaxen jar包,而 ...
- java.lang.NoClassDefFoundError: org/jaxen/JaxenException解决方法
在使用dom4j的xpath时出现java.lang.NoClassDefFoundError: org/jaxen/JaxenException的异常,原因是dom4j引用了jaxen jar包,而 ...
- tomcat运行JSP时产生的错误:”javax.servlet.servletexception: java.lang.nosuchmethoderror”
这个错误其实是多次重复编译JAVA文件导致的,需要clean操作,简单的来说就是删除tomcat下work文件夹中工作空间,也可以理解为自己的虚拟路径,比如我运行的jsp的路径:localhost:8 ...
随机推荐
- HDC与CDC相互转换
转自loop_k原文 HDC与CDC相互转换 概念 首先说一下什么是DC(设备描述表):Windows应用程序通过为指定设备(屏幕,打印机等)创建一个设备描述表(Device Context, DC) ...
- http转成https
1.在阿里云服务器上购买一个AC证书,将证书下载下来 2.解压放在tomcat目录下,cert文件夹是我自己建的 3.修改tomcat的配置文件上面那个原来是被注掉的放开 把端口改为443,htt ...
- excel 分类汇总函数
1.先用数组公式对单元格区域 B3:B39 ,进行提取去重复非空调单元格信息.单元格B52数组公式: =INDIRECT(TEXT(MIN(IF((COUNTIF(B$51:B51,B$3:B$39) ...
- UP Board USB无线网卡选购指南
前言 原创文章,转载引用务必注明链接,水平有限,欢迎指正. 本文环境:ubilinux 3.0 kernel 4.4.0 本文使用Markdown写成,为获得更好的阅读体验和正常的图片.链接,请访问我 ...
- C++ string 实现大整数相加减
随意两个大整数的加减算法.可自己主动推断正负号.代码例如以下: #include <iostream> #include <vector> #include <cstri ...
- (testng多个class文件执行时混乱,不是等一个class内的所有methods执行完再去执行下一个class内的内容)问题的解决
问题描述如下: We use TestNG and Selenium WebDriver to test our web application. Now our problem is that we ...
- 甘特图——Excel搞定
1. 甘特图 概念 甘特图就是条形图的一种. 甘特图是基于作业排序的目的,将活动与时间联系起来的最早尝试之中的一个. 这是什么意思呢?也就是说甘特图用来表示什么时间做什么事情,相当于一个计划安排.并且 ...
- block-循环引用
在ARC机制下,app的内存管理由操作系统进行管理,不须要程序猿手动的管理内存,方便了开发.虽然,自己主动释放内存非常方便.可是并不是绝对安全,绝对不会产生内存泄露. 大部分导致iOS对象无法按预期释 ...
- java上下文Context类
Context在Java中的出现是如此频繁,但其中文翻译"上下文"又是如此诡异拗口,因此导致很多人不是很了解Context的具体含义是指什么,所以很有必要来深究一下这词的含义. 先 ...
- 阿里Java编程规范 学习笔记
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...