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. sql 添加自定义排序

    Mysql : SELECT (@i:=@i+1) AS ind ,字段 FROM 表名 别名, (SELECT @i:=0) t WHERE `IsDeleted` = 0; Oracle: 本就有 ...

  2. mini-uboot 启动过程简单分析

    单片机有最小系统,所谓最小系统,就是单片机能正常工作所需要的最少外设.对于Uboot来说,同样有个最小系统,因为Uboot最主要的功能就是引导内核.下面我们通过一个简单的Mini-Uboot来分析Ub ...

  3. [转]Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案

    原文地址:http://www.cnblogs.com/gb2013/archive/2013/03/05/SecurityEnhancementsInTheCRT.html 在VS 2012 中编译 ...

  4. Linux下Tomcat VM參数改动

    不可行的方法 最初我直接改动catalina.sh, 将JAVA_OPTS变量加上了 -server -Xms1G -Xmx1G -XX:+UserG1GC 最初看起来没啥问题,可是当服务器运行几天后 ...

  5. hadoop优质链接

    http://wiki.apache.org/hadoop/FAQ

  6. Spring Boot 使用Java代码创建Bean并注冊到Spring中

    从 Spring3.0 開始,添加了一种新的途经来配置Bean Definition,这就是通过 Java Code 配置 Bean Definition. 与Xml和Annotation两种配置方式 ...

  7. Flash/Flex获取外部参数

    Part One:Flex程序如何获取html容器传递的URL参数值 我们经常在Flex程序需要用从外部html向swf文件传递参数,(类似 test.html?name=jex&addres ...

  8. 【转载】C#中的泛型

    1.1 C#中的泛型 .Net 1.1版本最受诟病的一个缺陷就是没有提供对泛型的支持.通过使用泛型,我们可以极大地提高代码的重用度,同时还可以获得强类型的支持,避免了隐式的装箱.拆箱,在一定程度上提升 ...

  9. 这样看ACM是不是更好?

    如果搞ACM只是为了拿奖,为了保研,这样太功利,整个过程都会变得没意思.我说过我同时看中过程和结果. 其实ACM解题也不是那么没意思,每次AC都有一种非常棒的成就感,每个题目就像是一个解谜游戏,完成了 ...

  10. mybatis 简单项目步骤

    mybatis.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configura ...