package s2jsp.lg.entity;public class User {
    private int    uId    =  1;     //用来唯一标识用户
    private String uName  =  null;//用户名 
private String uPass  =  "accp";//用户密码
    private int    gender =  2;    //性别,1是女,2是男
    private String regTime;
    public String getRegTime() {
return regTime;
} public void setRegTime(String regTime) {
this.regTime = regTime;
} private String head; 
 
public String getHead() {
return head;
} public void setHead(String head) {
this.head = head;
} public int getGender() {
        return gender;
    }
    
    public void setGender(int gender) {
        this.gender = gender;
    }    public int getUId() {
        return uId;
    }
    
    public void setUId(int id) {
        uId = id;
    }
    public String getUName() {
return uName;
} public void setUName(String name) {
 this.uName = name;

     
    
    public String getUPass() {
        return uPass;
    }
    
    public void setUPass(String uPass) {
        this.uPass = uPass;
    }
    
    public void getUserInfo() {
        System.out.println("====用户信息====");
        System.out.println("用户名:"   + uName);
        System.out.println("用户密码:" + uPass);
        char sex = gender==1 ? '女':'男';    //条件运算符,等同于条件语句,条件是性别是否等于1
        System.out.println("性别:"     + sex + "\n");
    }
}
----------------------------------------------------------------------------------------------------------
package s2jsp.lg.dao.impl;import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;import s2jsp.lg.dao.UserDao;
import s2jsp.lg.entity.User;public class UserDaoImpl extends BaseDao implements UserDao {
    private Connection        conn  = null;       // 保存数据库连接
    private PreparedStatement pstmt = null;       // 用于执行SQL语句
    private ResultSet         rs    = null;       // 用户保存查询结果集    /**
     * 增加用户
     * @param user
     * @return 增加条数
     */
    public int addUser(User user) {
        String   sql  = "insert into TBL_USER(uname,upass,gender,head,regTime) values(?,?,"+user.getGender()+",?,?)";
        String   time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());  // 取得日期时间
        String[] parm = { user.getUName(), user.getUPass(),user.getHead(),time };
        return this.executeSQL(sql, parm);        // 执行sql,并返回影响行数
    }    
    
    /**
     * 修改用户密码
     * @param user
     * @return 更新条数
     */
    public int updateUser(User user){
        String   sql  = "update TBL_USER set upass=? where uname=?";
        String[] parm = { user.getUPass(),user.getUName() };
        return this.executeSQL(sql, parm);        // 执行sql,并返回影响行数
    }
    
    /**
     * 根据用户名查找用户
     * @param uName
     * @return 根据用户名查询的用户对象
     */
    public User findUser(String uName) {
        String sql  = "select * from TBL_USER where uName=?";
        User   user = null;
        try {
            conn  = this.getConn();                // 取得数据库连接
            pstmt = conn.prepareStatement(sql);    // 取得PreparedStatement对象
            pstmt.setString(1, uName);             // 设置参数
            rs    = pstmt.executeQuery();          // 执行SQL取得结果集
            while( rs.next() ) {
                user = new User();
                user.setUId( rs.getInt("uId") );
                user.setUName( rs.getString("uName") );
                user.setUPass( rs.getString("uPass") );
                user.setGender(rs.getInt("gender"));
                user.setHead( rs.getString("head") );
                user.setRegTime( rs.getString("regTime") );
            }
        } catch (Exception e) {
            e.printStackTrace();                   // 处理异常
        } finally {
            this.closeAll(conn, pstmt, rs);
        }
        return user;
    }
    
    /**
     * 根据用户id查找用户
     * @param uId
     * @return 根据uid查询的用户对象
     */
    public User findUser(int uId) {
        String sql  = "select * from TBL_USER where uId=?";
        User   user = null;
        try {
            conn  = this.getConn();                  //取得数据库连接
            pstmt = conn.prepareStatement(sql);       //取得PreparedStatement对象
            pstmt.setInt(1, uId);                     //设置参数
            rs    = pstmt.executeQuery();             //执行SQL取得结果集
            while( rs.next() ) {
                user = new User();
                user.setUId( rs.getInt("uId") );
                user.setUName( rs.getString("uName") );
                user.setUPass( rs.getString("uPass") );
                user.setGender(rs.getInt("gender"));
                user.setHead( rs.getString("head") );
                user.setRegTime( rs.getString("regTime") );
            }
        } catch (Exception e) {
            e.printStackTrace();                     // 处理异常
        } finally {
            this.closeAll(conn, pstmt, rs);         // 释放资源
        }        
        return user;
    }
}
-------------------------------------------------------------------------------------------------------------
<%@ page language="java" pageEncoding="GBK"
import="java.util.*,
s2jsp.lg.entity.*,
s2jsp.lg.dao.*,
s2jsp.lg.dao.impl.*"%>
<%
TopicDao topicDao  = new TopicDaoImpl();                                  // 得到主题Dao的实例
ReplyDao replyDao  = new ReplyDaoImpl();                                  // 得到回复Dao的实例
UserDao  userDao   = new UserDaoImpl();                                   // 得到用户Dao的实例
int      topicId   = 1;                                                   // 主题id暂固定为1
int      p         = 1;                                                   // 页数暂固定为1
Topic    topic     = topicDao.findTopic( topicId );                        // 取得主题信息
User     topicUser = userDao.findUser( topic.getUid() );                   // 取得主题作者
List     listReply = replyDao.findListReply( p,topicId );                  // 取得该主题的回复列表
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML>
<HEAD>
<TITLE>青鸟学员论坛--看贴</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gbk">
<Link rel="stylesheet" type="text/css" href="style/style.css" />
</HEAD><BODY>
<DIV>
<IMG src="image/logo.gif">
</DIV><!--      用户信息、登录、注册        --><DIV class="h">
您尚未 <a href="login.jsp">登录</a>
&nbsp;| &nbsp; <A href="reg.jsp">注册</A> |
</DIV><!--      主体        -->
<DIV><br/>
<!--      导航        -->
<DIV>
&gt;&gt;<B><a href="index.jsp">论坛首页</a></B>&gt;&gt;
<B><a href="list.jsp">JSP技术</a></B>
</DIV>
<br/>
<!--      回复、新帖        -->
<DIV>
<A href="post.jsp"><IMG src="image/reply.gif"  border="0"></A> 
<A href="post.jsp"><IMG src="image/post.gif"   border="0"></A>
</DIV>
<!--         翻 页         -->
<DIV>
<a href="detail.jsp">上一页</a>|
<a href="detail.jsp">下一页</a>
</DIV>
<!--      本页主题的标题        -->
<DIV>
<TABLE cellSpacing="0" cellPadding="0" width="100%">
<TR>
<TH class="h">本页主题: <%=topic.getTitle() %></TH>
</TR>
<TR class="tr2">
<TD>&nbsp;</TD>
</TR>
</TABLE>
</DIV>

<!--      主题        -->
<%
if(p==1){ 
%>
<DIV class="t">
<TABLE style="BORDER-TOP-WIDTH: 0px; TABLE-LAYOUT: fixed" cellSpacing="0" cellPadding="0" width="100%">
<TR class="tr1">
<TH style="WIDTH: 20%">
<B></B><BR/>
<image src="image/head/<%=topicUser.getHead()%> "/><BR/>
注册:<%=topicUser.getRegTime().substring(0,10) %><BR/>
</TH>
<TH>
<H4><%=topic.getTitle() %></H4>
<DIV><%=topic.getContent() %></DIV>
<DIV class="tipad gray">
发表:[<%=topic.getPublishTime().substring(0,16) %>] &nbsp;
最后修改:[<%=topic.getModifyTime().substring(0,16) %>]
</DIV>
</TH>
</TR>
</TABLE>
</DIV>

<!--      回复        -->
<%
}
for( int i=0; i<listReply.size(); i++ ) {
Reply reply     = (Reply)listReply.get(i);                   // 循环取得回复信息
User  replyUser = (User)userDao.findUser( reply.getUid() );  // 取得回复的作者
%>
<DIV class="t">
<TABLE style="BORDER-TOP-WIDTH: 0px; TABLE-LAYOUT: fixed" cellSpacing="0" cellPadding="0" width="100%">
<TR class="tr1">
<TH style="WIDTH: 20%">
<B><%=replyUser.getUName() %></B><BR/><BR/>
<image src="image/head/<%=replyUser.getHead()%>"/><BR/>
注册:<%=topicUser.getRegTime().substring(0,10) %><BR/>
</TH>
<TH>
<H4><%=reply.getTitle() %></H4>
<DIV><%=reply.getContent() %></DIV>
<DIV class="tipad gray">
发表:[<%=reply.getPublishTime().substring(0,16) %>] &nbsp;
最后修改:[<%=topic.getModifyTime().substring(0,16) %>]
<A href="">[删除]</A>
<A href="">[修改]</A>
</DIV>
</TH>
</TR>
</TABLE>
</DIV>
<%} %>
<DIV>
<a href="detail.jsp">上一页</a>|
<a href="detail.jsp">下一页</a>
</DIV>
</DIV><!--      声明        -->
<BR>
<CENTER class="gray">2007 Beijing Aptech Beida Jade Bird
Information Technology Co.,Ltd 版权所有</CENTER>
</BODY>
</HTML>
--------------------------------------------------------------------------------------------------------------
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /detail.jsp:7673:  <TR class="tr1">
74:  <TH style="WIDTH: 20%">
75:  <B></B><BR/>
76:  <image src="image/head/<%=topicUser.getHead()%> "/><BR/>
77:  注册:<%=topicUser.getRegTime().substring(0,10) %><BR/>
78:  </TH>
79:  <TH>