tomcat白屏~~求助!!
我用tomcat运行写好的velocity模版,出现白屏,不提示错误,让我很郁闷...
文件目录如下C:\Tomcat 5.0\webapps\table
TestVelocity.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 ", "john@some.domain ", true ) );
user.add( new User( " Alice ", "alice@other.domain ", false ) );
user.add( new User( "Tom ", "tom@other.domain ", true ) );
user.add( new User( "Elisa ", "elisa@some.domain ", false ) );
user.add( new User( "Zine ", "zine@other.domain ", true ) );
/*
User u=new User();
u.setName( "John ");
u.setEmailAddress( "john@some.domain ");
u.setMale(true);
userlist.put(u.getName(),u);
u.setName( "Alice ");
u.setEmailAddress( "alice@other.domain ");
u.setMale(false);
userlist.put(u.getName(),u);
u.setName( "Tom ");
u.setEmailAddress( "tom@other.domain ");
u.setMale(true);
userlist.put(u.getName(),u);
u.setName( "Elisa ");
u.setEmailAddress( "elisa@some.domain ");
u.setMale(false);
userlist.put(u.getName(),u);
u.setName( "Zine ");
u.setEmailAddress( "zine@other.domain ");
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>
找高人指点阿...
[解决办法]
顶个
[解决办法]
换个JDK试试。应该是JDK的问题。
[解决办法]
velocity模版在执行过程中出现任何一点错误都会出现白屏的,我稍微看了一下你的程序,想问一下你这个#foreach($userInstance in $user)里面的$user好像跟你组装进来的这个:context.put( "userlist ",userlist);的userlist不符哦?是不是写错了。。。是不是应该是:
#foreach($userInstance in $userlist)阿?检查下咯。。还有就是你注释了那么多代码是什么回事?是注释后出错还是注释前出错?
[解决办法]
可能是Tomcat的问题,我以前也遇见过,换个Tomcat试下