LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 843|回复: 1

out.print与<%=%>的困惑

[复制链接]
发表于 2006-10-20 11:45:27 | 显示全部楼层 |阅读模式
在jsp中用javabean出现错误

模仿了两个java,用意是通过传进来的一个Id值显示整条信息的详细。
ShowNewsById.java

package com.air.ui;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.NamingException;
import com.air.util.DBconn;



public class ShowNewsById{
public ShowNewsById(){

}
public CheckNews ILoveYou(int Id)
throws SQLException, NamingException, ClassNotFoundException
{
String sql="select * from freenews where Id="+Id;
DBconn db=new DBconn();
ResultSet rs=db.executeQuery(sql);
rs.next();
CheckNews DoYouLoveMe=new CheckNews();
DoYouLoveMe.setAuthor(rs.getString("Author"));
DoYouLoveMe.setBigC(rs.getInt("BigC"));
DoYouLoveMe.setSmallC(rs.getInt("SmallC"));
DoYouLoveMe.setTitle(rs.getString("Title"));
DoYouLoveMe.setEditor(rs.getString("Editor"));
DoYouLoveMe.setContent(rs.getString("Content"));
DoYouLoveMe.setComment(rs.getString("Comment"));
DoYouLoveMe.setCount(rs.getInt("Count"));
DoYouLoveMe.setIsFree(rs.getInt("IsFree"));
DoYouLoveMe.setKeywords(rs.getString("Keywords"));
// DoYouLoveMe.setNewsDate(rs.getTime("NewsDate"));
rs.close();
db.close();
return Doq;
}
}


CheckNews.java


package com.air.ui;
import com.air.util.AirDateTime;

public class CheckNews{

private int Id;
private String Title;
private String Content;
private String Author;
private String Editor;
private AirDateTime NewsDate;
private int Count;
private String Comment;
private String Keywords;
private int BigC;
private int SmallC;
private int IsFree;



public CheckNews(){
}



public void setId(int Id){
this.Id=Id;
}
public int getId(){
return Id;
}
public String getAuthor() {
return Author;
}
public void setAuthor(String author) {
Author = author;
}
public int getBigC() {
return BigC;
}
public void setBigC(int bigC) {
BigC = bigC;
}
public String getComment() {
return Comment;
}
public void setComment(String comment) {
Comment = comment;
}
public String getContent() {
return Content;
}
public void setContent(String content) {
Content = content;
}
public int getCount() {
return Count;
}
public void setCount(int count) {
Count = count;
}
public String getEditor() {
return Editor;
}
public void setEditor(String editor) {
Editor = editor;
}
public int getIsFree() {
return IsFree;
}
public void setIsFree(int isFree) {
IsFree = isFree;
}
public String getKeywords() {
return Keywords;
}
public void setKeywords(String keywords) {
Keywords = keywords;
}
public AirDateTime getNewsDate() {
return NewsDate;
}
public void setNewsDate(AirDateTime newsDate) {
NewsDate = newsDate;
}
public int getSmallC() {
return SmallC;
}
public void setSmallC(int smallC) {
SmallC = smallC;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}




}

问题是在jsp页面调用的时候,在\<\%\%\>中用“out.print(DoYouLoveMe.getTitle());”可以在网页上打印出来,但是“\<\%=DoYouLoveMe.getTitle()\%\>”就会报错“An error occurred at line: 82 in the jsp file: /BackAdmin/shownews.jsp
Generated servlet error:
C:\eclipse\workspace\Air\work\org\apache\jsp\BackAdmin\shownews_jsp.java:138: cannot resolve symbol
symbol : variable DoYouLoveMe
location: class org.apache.jsp.BackAdmin.shownews_jsp
out.print(DoYouLoveMe.getTitle());

DoYouLoveMe怎么会没定义呢?
 楼主| 发表于 2006-10-23 11:19:40 | 显示全部楼层

20061019问题的解决

  那日所提的问题,原来是由于一个\<%}\%>,应该把这个东西放在比较后面一些,就是出现\<%=\%>标记的后面,以便完成一个总的{},以前由于我匆匆就把它放在了上面,就是new新对象完成以后,所以下面的\<%=\%>计算表达式的值当然就会出现”没有定义DoYouLoveMe“的错误了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表