再次谢谢yangxiao_jiang。但我不是不了解是怎么回事。比如我们在Delphi里调试的时候,如果没有按F7它是不会跟踪到VCL里的代码的。但ECLIPSE里就会这样吗?还是说我的代码有问题呢?yangxiao_jiang能帮我看一下这个代码吗?我也是从网上拷下来的:
get.jsp
<html>
<body>
<form>
<jsp:useBean id="staffBean"
class="StaffBean"
scope="session"
/>
<table border="1">
<tbody>
<tr>
<td width="120">Employee ID</td>
<td width="100">Name</td>
</tr>
<tr>
<td><jsp:getProperty name="staffBean"
property="ID"
/></td>
<td><jsp:getProperty name="staffBean"
property="name"
/></td>
</tr>
</tbody>
</table>
<form action="/servlet/StaffServlet"
method="POST">
<input type=submit value="Detail">
</form>
</body>
</html>
post.jsp
<jsp:useBean id="staffBean"
class="jpc.StaffBean"
scope="session"
/>
<table border="1"><tbody>
<tr>
<td width="120">Employee ID</td>
<td width="100">Name</td>
<td width="100">Department</td>
<td width="50">Job Title</td>
<td width="200">Years of Continuous Employment</td>
</tr>
<tr>
<td><jsp:getProperty name="staffBean"
property="ID"
/></td>
<td><jsp:getProperty name="staffBean"
property="name"
/></td>
<td><jsp:getProperty name="staffBean"
property="dept"
/></td>
<td><jsp:getProperty name="staffBean"
property="job"
/></td>
<td><jsp:getProperty name="staffBean"
property="years"
/></td>
</tr>
</tbody></table>
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class StaffServlet extends HttpServlet {
public voiddo
Get(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
StaffBean bean = new StaffBean();
bean.setID("10"
;
bean.setName("Sanders"
;
HttpSession session = req.getSession(true);
session.setAttribute("staffBean", bean);
ServletContext ctxt = getServletContext();
RequestDispatcher rd = ctxt.getRequestDispatcher("/jsp/Get.jsp"
;
if(rd != null){
rd.forward(req, res);
}
}
public voiddo
Post(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
HttpSession session = req.getSession(true);
StaffBean bean = (StaffBean)session.getAttribute("staffBean"
;
bean.setDept("SERVICE DIV."
;
bean.setJob("ITS"
;
bean.setYears("7"
;
ServletContext ctxt = getServletContext();
RequestDispatcher rd = ctxt.getRequestDispatcher("/jsp/Post.jsp"
;
if(rd != null){
rd.forward(req, res);
}
}
}
public class StaffBean {
private String ID;
private String name;
private String dept;
private String job;
private String years;
public StaffBean () {
}
public String getID() {
return ID;
}
public void setID(String str) {
ID = str;
}
public String getName() {
return name;
}
public void setName(String str) {
name = str;
}
public String getDept() {
return dept;
}
public void setDept(String str) {
dept = str;
}
public String getJob() {
return job;
}
public void setJob(String str) {
job = str;
}
public String getYears() {
return years;
}
public void setYears(String str) {
years = str;
}
}
非常感谢!