package com;
//此JavaBean代表了添加新闻页面的数据
public class NewsVO
{
private String id,content;
private java.sql.Date date;
public String getId()
{
return this.id;
}
public String getContent()
{
return this.content;
}
public java.sql.Date getDate()
{
return this.date;
}
public void setId(String id)
{
this.id=id;
}
public void setContent(String content)
{
this.content=content;
}
public void setDate(java.sql.Date date)
{
this.date=date;
}
}
package com;
import java.sql.*;
import java.util.*;
public class NewsBean
{
public Connection con;
NewsVO msg;
//获得数据库连接
public NewsBean()
{
String CLASSFORNAME="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String SERVANDDB="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatebaseName=website";
String USER="bn";
String PWD="bn";
try
{
Class.forName(CLASSFORNAME);
con=DriverManager.getConnection(SERVANDDB,USER,PWD);
}
catch(Exception e)
{
e.printStackTrace();
}
}
//设置属性
public void setNews(NewsVO msg)
{
this.msg=msg;
}
//增加新闻
public void addNews()throws Exception
{
try
{
PreparedStatement stm=con.prepareStatement("insert into news values(?,?,?)");
stm.setString(1,msg.getId());
stm.setString(2,msg.getContent());
stm.setDate(3,new java.sql.Date(new java.util.Date().getTime()));
try
{
stm.executeQuery();
}
catch(Exception e)
{
}
//关闭数据库
con.close();
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
//获得所有新闻,并返回结果到相应JSP页面
public Collection getNews()throws Exception
{
Collection ret=new ArrayList();
try
{
Statement stm=con.createStatement();
ResultSet result=stm.executeQuery("select count(*) from news");
int news_count=0;
if (result.next())
{
news_count=result.getInt(1);
//result.close();
}
if(news_count>0)
{
result=stm.executeQuery("select * from news order by time desc");
while(result.next())
{
String id=result.getString("title");
String content=result.getString("content");
java.sql.Date date=result.getDate("time");
NewsVO news=new NewsVO();
news.setId(id);
news.setContent(content);
news.setDate(date);
ret.add(news);
}
result.close();
stm.close();
}
con.close();
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
return ret;
}
}
//JSP调用JAVABEAN 将数据显示
<%@ page import="java.sql.*,com.*,java.util.*" %>
<jsp:useBean id="newsBean" class="com.newsBean" scope="page"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>show the news</title>
</head>
<body>
<center>
<p align="center">
[<a href="addnews.htm" class=main>添加新闻</a>]</p>
<hr>
<table border=1>
<tr><td>新闻标题</td><td>添加时间</td><td>操作</td></tr>
<%
Collection news=newsBean.getNews();
System.out.println("hello");
Iterator it=news.iterator();
while(it.hasNext())
{
newsVO news=(newsVO)it.next();
%>
<tr><td><%=news.getId()%></td></tr>
<tr><td><%=news.getDate().toLocalString()%></td></tr>
}
<tr><td><%out.println("你好");%></td></tr>
</table>
</center>
</body>
</html>
//错误提示:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
No Java compiler was found to compile the generated source for the JSP.
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:128)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:413)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.12
我已经将tools.jar文件 拷贝到了TOMCAT的相应目录下,可还是提示这个错误!谢谢!!
19 个解决方案
#1
org.apache.jasper.JasperException: Unable to compile class for JSP
配置的问题!
配置的问题!
#2
配置应该没有问题的,其他没有出现错误呀!
#3
要设置环境变量,JAVA_HOME指到你的JDK目录
#4
并要从新启动TOMCAT
#5
配置应该没有问题,我做的其他类似的程序能够运行的,真是晕倒,哪位高手能不能仔细看一下我的程序是不是有问题?感激不尽!!!
#6
No Java compiler was found to compile the generated source for the JSP.
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.
说明你JAVA_HOME没有设置好或者,你的classpath没有包含tools.jar
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.
说明你JAVA_HOME没有设置好或者,你的classpath没有包含tools.jar
#7
你的NewsVO 好像并没有被导入class NewsBean文件中
#8
在classpath下只要放下tools.jar路径?怎么还是没用?
#9
格式不对吧!!!
要在tools.jar后面加上:.
要在tools.jar后面加上:.
#10
是进入哪个页面时候报这个错?还是进入任何页面都会报这个错?
#11
类的路径不对吧,是不是放在默认的class目录下了?还有数据库驱动没有加载吧,你试试在bean里加上import com.microsoft.jdbc.sqlserver.SQLServerDriver;
#12
要设置环境变量,JAVA_HOME指到你的JDK目录
#13
在classpath中加上tools.jar的路径
#14
tools.jar考到common/lib?
#15
唉,我也出这毛病。不知道咋整的,我显示的是空指针。NN的。CSDN里的高手都不出现。。
同情啊,兄弟/。。
同情啊,兄弟/。。
#16
up
#17
显然是环境变量设置问题
#18
谢谢大家,可是我还是没有搞定这个问题,我快晕了,麻烦高手仔细看一下,谢谢!!!
#19
作个只现实时间的jsp,运行看看!不就知道是不是配置的问题了!
#20
#1
org.apache.jasper.JasperException: Unable to compile class for JSP
配置的问题!
配置的问题!
#2
配置应该没有问题的,其他没有出现错误呀!
#3
要设置环境变量,JAVA_HOME指到你的JDK目录
#4
并要从新启动TOMCAT
#5
配置应该没有问题,我做的其他类似的程序能够运行的,真是晕倒,哪位高手能不能仔细看一下我的程序是不是有问题?感激不尽!!!
#6
No Java compiler was found to compile the generated source for the JSP.
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.
说明你JAVA_HOME没有设置好或者,你的classpath没有包含tools.jar
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.
说明你JAVA_HOME没有设置好或者,你的classpath没有包含tools.jar
#7
你的NewsVO 好像并没有被导入class NewsBean文件中
#8
在classpath下只要放下tools.jar路径?怎么还是没用?
#9
格式不对吧!!!
要在tools.jar后面加上:.
要在tools.jar后面加上:.
#10
是进入哪个页面时候报这个错?还是进入任何页面都会报这个错?
#11
类的路径不对吧,是不是放在默认的class目录下了?还有数据库驱动没有加载吧,你试试在bean里加上import com.microsoft.jdbc.sqlserver.SQLServerDriver;
#12
要设置环境变量,JAVA_HOME指到你的JDK目录
#13
在classpath中加上tools.jar的路径
#14
tools.jar考到common/lib?
#15
唉,我也出这毛病。不知道咋整的,我显示的是空指针。NN的。CSDN里的高手都不出现。。
同情啊,兄弟/。。
同情啊,兄弟/。。
#16
up
#17
显然是环境变量设置问题
#18
谢谢大家,可是我还是没有搞定这个问题,我快晕了,麻烦高手仔细看一下,谢谢!!!
#19
作个只现实时间的jsp,运行看看!不就知道是不是配置的问题了!