java代码
 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解决方法的更多相关文章

  1. HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag

    我在项目中导入了jar,还是不能使用EL表达式,一运行就出现了下面的额错误: org.apache.jasper.JasperException: javax.servlet.ServletExcep ...

  2. javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver错误解决办法

    今天不用eclipse.myeclipse等开发工具,纯手写JSP页面(有点作死)时突然出现以前从来没遇到过的问题,报错如下: HTTP Status 500 - java.lang.NoClassD ...

  3. 关于jsp web项目中的javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver错误

    错误: javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver org.apache.j ...

  4. 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 ...

  5. HTTP Status 500 - javax.servlet.ServletException

    运行某个jsp页面时提示 type Exception report message javax.servlet.ServletException: java.lang.NoClassDefFound ...

  6. javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation:

    javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving ...

  7. 类似java.lang.NoClassDefFoundError: org/jaxen/JaxenException解决方法

    在使用dom4j的xpath时出现java.lang.NoClassDefFoundError: org/jaxen/JaxenException的异常,原因是dom4j引用了jaxen jar包,而 ...

  8. java.lang.NoClassDefFoundError: org/jaxen/JaxenException解决方法

    在使用dom4j的xpath时出现java.lang.NoClassDefFoundError: org/jaxen/JaxenException的异常,原因是dom4j引用了jaxen jar包,而 ...

  9. tomcat运行JSP时产生的错误:”javax.servlet.servletexception: java.lang.nosuchmethoderror”

    这个错误其实是多次重复编译JAVA文件导致的,需要clean操作,简单的来说就是删除tomcat下work文件夹中工作空间,也可以理解为自己的虚拟路径,比如我运行的jsp的路径:localhost:8 ...

随机推荐

  1. svm、logistic regression对比

    相同点:都是线性分类算法 不同点: 1.损失函数不同 LR:基于“给定x和参数,y服从二项分布”的假设,由极大似然估计推导 SVM: hinge loss + L2 regularization的标准 ...

  2. Hash分析

    分析Hash 列表内容 Hash表中的一些原理/概念,及依据这些原理/概念,自己设计一个用来存放/查找数据的Hash表,而且与JDK中的HashMap类进行比較. 我们分一下七个步骤来进行. Hash ...

  3. iOS 获取appstore 版本

    项目上线以后一般都涉及到升级.那么iOS 怎样从appstore获取到版本 事实上非常easy NSString *url = [[NSString alloc] initWithFormat:@&q ...

  4. PHPMailer发送邮件乱码

    PHPMailer发送邮件乱码, $mail->CharSet="GB2312";$mail->Encoding = "base64"; 设成这样不 ...

  5. Mmseg中文分词算法解析

    Mmseg中文分词算法解析 @author linjiexing 开发中文搜索和中文词库语义自己主动识别的时候,我採用都是基于mmseg中文分词算法开发的Jcseg开源project.使用场景涉及搜索 ...

  6. testng 工程报错java.net.SocketException

    报错如下: java.net.SocketException: Software caused connection abort: socket write error at java.net.Soc ...

  7. 模式识别之聚类算法k-均值---k-均值聚类算法c实现

    //写个简单的先练习一下,测试通过 //k-均值聚类算法C语言版   #include <stdlib.h>      #include <stdio.h>      #inc ...

  8. 深入浅出 - Android系统移植与平台开发(九)- Android系统system_server及Home启动

    3.3 Zygote守护进程与system_server进程 Android的执行环境和Java执行环境有着本质的差别,在Android系统中每一个应用程序都是一独立的进程,当一个进程死掉时,不会影响 ...

  9. 设计模式学习笔记——Mediator中介者模式

    将众多对象之间的网状关系转为全部通过一个中间对象间接发生关系,此中间对象为中介者. 看图最直观: 作用不言而喻,就是降低对象之间的耦合度,乃至降低了整个系统的复杂度. 有点象代理模式,更象外观模式:

  10. CSS3 Selector

    每个前端工程师可能每天都会写一些css,其中选择器是很主要的一部分.但是,大家可能每天写的大多是#id,.class这样的选择器,这并不稀奇,但是如果我们了解并且熟用css3为我们提供的强大并且优雅的 ...