我用tomcat运行写好的velocity模版,出现白屏,不提示错误,让我很郁闷...文件目录如下C:\Tomcat 5.0\webapps\tableTestVelocity.java代码
package cn.ac.ict;import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.velocity.*;
import org.apache.velocity.context.*;
import org.apache.velocity.servlet.*;
import org.apache.velocity.app.*;
import org.apache.velocity.exception.*;
import javax.swing.table.*; public class TestVelocity extends VelocityServlet{
protected Properties loadConfiguration(ServletConfig config)
throws IOException,FileNotFoundException
{
Properties p=new Properties();
String path=config.getServletContext().getRealPath("/");
if(path==null)
{
System.out.println("TestVelocity.loadConfiguration():"+
"unable to get the current webapp root.Using '/'.");
path="/";
}
p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,path);
p.setProperty("runtime.log",path+"velocity.log");
return p;
}
public Template handleRequest(HttpServletRequest request,HttpServletResponse response,Context context)
{
Template outty=null;
try
{
// Hashtable userlist=new Hashtable();
java.util.List user = new java.util.ArrayList(5);
user.add( new User( "John", "[email protected]", true ) );
user.add( new User( " Alice ", "[email protected]", false ) );
user.add( new User( "Tom", "[email protected]", true ) );
user.add( new User( "Elisa", "[email protected]", false ) );
user.add( new User( "Zine", "[email protected]", true ) );
/*
User u=new User();
u.setName("John");
u.setEmailAddress("[email protected]");
u.setMale(true);
userlist.put(u.getName(),u);
u.setName("Alice");
u.setEmailAddress("[email protected]");
u.setMale(false);
userlist.put(u.getName(),u);
u.setName("Tom");
u.setEmailAddress("[email protected]");
u.setMale(true);
userlist.put(u.getName(),u);
u.setName("Elisa");
u.setEmailAddress("[email protected]");
u.setMale(false);
userlist.put(u.getName(),u);
u.setName("Zine");
u.setEmailAddress("[email protected]");
u.setMale(true);
userlist.put(u.getName(),u);
context.put("userlist",userlist);*/
outty=getTemplate("UserTable.vm");
}
catch(ParseErrorException ex1){
System.out.println("TestVelocity:parse error for template"+ex1);
}catch(ResourceNotFoundException ex2){
System.out.println("TestVelocity:template not found"+ex2);
}catch(Exception ex3){
System.out.println("TestVelocity:error"+ex3);
}
return outty;
}
}User.java代码
package cn.ac.ict;public class User {
private String name;
private String emailAddress;
private boolean male; public String getEmailAddress() {
return emailAddress;
} public void setEmailAddress(String address) {
this.emailAddress = address;
} public boolean isMale() {
return male;
} public void setMale(boolean male) {
this.male = male;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public User( String name, String emailAddress, boolean male ) {
this.name = name;
this.emailAddress = emailAddress;
this.male = male;
} }
User.vm代码
<html>
<title>TestVelocity</title>
<body>
<h1>采用 table 的形式显示:</h1><br/>
<table border=1>
<tr>
<td>Name</td>
<td>EMailAddress</td>
<td>Male or Female</td>
</tr>
#foreach($userInstance in $user)
<tr>
<td>$userInstance.name</td>
<td>$userInstance.emailAddress</td>
#if($userInstance.male)
<td bgcolor="blue">男</td>
#else
<td bgcolor="red">女</td>
</tr>
#end
</table>
</body>
</html>找高人指点阿...
package cn.ac.ict;import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.velocity.*;
import org.apache.velocity.context.*;
import org.apache.velocity.servlet.*;
import org.apache.velocity.app.*;
import org.apache.velocity.exception.*;
import javax.swing.table.*; public class TestVelocity extends VelocityServlet{
protected Properties loadConfiguration(ServletConfig config)
throws IOException,FileNotFoundException
{
Properties p=new Properties();
String path=config.getServletContext().getRealPath("/");
if(path==null)
{
System.out.println("TestVelocity.loadConfiguration():"+
"unable to get the current webapp root.Using '/'.");
path="/";
}
p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,path);
p.setProperty("runtime.log",path+"velocity.log");
return p;
}
public Template handleRequest(HttpServletRequest request,HttpServletResponse response,Context context)
{
Template outty=null;
try
{
// Hashtable userlist=new Hashtable();
java.util.List user = new java.util.ArrayList(5);
user.add( new User( "John", "[email protected]", true ) );
user.add( new User( " Alice ", "[email protected]", false ) );
user.add( new User( "Tom", "[email protected]", true ) );
user.add( new User( "Elisa", "[email protected]", false ) );
user.add( new User( "Zine", "[email protected]", true ) );
/*
User u=new User();
u.setName("John");
u.setEmailAddress("[email protected]");
u.setMale(true);
userlist.put(u.getName(),u);
u.setName("Alice");
u.setEmailAddress("[email protected]");
u.setMale(false);
userlist.put(u.getName(),u);
u.setName("Tom");
u.setEmailAddress("[email protected]");
u.setMale(true);
userlist.put(u.getName(),u);
u.setName("Elisa");
u.setEmailAddress("[email protected]");
u.setMale(false);
userlist.put(u.getName(),u);
u.setName("Zine");
u.setEmailAddress("[email protected]");
u.setMale(true);
userlist.put(u.getName(),u);
context.put("userlist",userlist);*/
outty=getTemplate("UserTable.vm");
}
catch(ParseErrorException ex1){
System.out.println("TestVelocity:parse error for template"+ex1);
}catch(ResourceNotFoundException ex2){
System.out.println("TestVelocity:template not found"+ex2);
}catch(Exception ex3){
System.out.println("TestVelocity:error"+ex3);
}
return outty;
}
}User.java代码
package cn.ac.ict;public class User {
private String name;
private String emailAddress;
private boolean male; public String getEmailAddress() {
return emailAddress;
} public void setEmailAddress(String address) {
this.emailAddress = address;
} public boolean isMale() {
return male;
} public void setMale(boolean male) {
this.male = male;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public User( String name, String emailAddress, boolean male ) {
this.name = name;
this.emailAddress = emailAddress;
this.male = male;
} }
User.vm代码
<html>
<title>TestVelocity</title>
<body>
<h1>采用 table 的形式显示:</h1><br/>
<table border=1>
<tr>
<td>Name</td>
<td>EMailAddress</td>
<td>Male or Female</td>
</tr>
#foreach($userInstance in $user)
<tr>
<td>$userInstance.name</td>
<td>$userInstance.emailAddress</td>
#if($userInstance.male)
<td bgcolor="blue">男</td>
#else
<td bgcolor="red">女</td>
</tr>
#end
</table>
</body>
</html>找高人指点阿...
解决方案 »
- 前台Ext无法获取struts2传递的json参数
- tomcat目录下找不到javabean
- 请教 怎么用xajax 返回js 到浏览器(能解决加分)
- 为什么呀??
- 如何在提交表单后,判断处理结果正确则弹出A对话框,如果错误则弹出B对话框?
- javax.servlet.jsp.JspException: Cannot find message resources under key org.apac
- JavaScript实现带参数跳转
- 关于Java加载视频控件的详细步骤
- 数据库连接池和事务会控制的问题
- 新手的问题
- 关于smartupload组件在Linux下中文乱码问题?高手进,在线等!
- 往数据库插入记录的问题
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:534)
root cause java.lang.UnsupportedClassVersionError: cn/ac/ict/TestVelocity (Unsupported major.minor version 49.0)
java.lang.ClassLoader.defineClass0(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:539)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:860)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1307)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:534)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.0.28
#foreach($userInstance in $userlist)阿?检查下咯。。还有就是你注释了那么多代码是什么回事?是注释后出错还是注释前出错?