这是我的表格。
form10.html
<form method="get" action="./a"><br>
FirstName: <input type="text" name="txtname"><br>
LastName:<input type="text" name="txtlast"><br>
Address:<input type="text" name="txtadd"><br>
<input type="submit" value="submit"><br>
</form>
这是我的 servlet 页面
Process10.java
PersonBean p1= new PersonBean();
p1.setfn(req.getParameter("txtname"));
fn=p1.getfn();
req.setAttribute("fn", fn);
p1.setln(req.getParameter("txtlast"));
ln=p1.getln();
req.setAttribute("ln", ln);
p1.setfn(req.getParameter("txtadd"));
ca=p1.getca();
req.setAttribute("ca", ca);
req.setAttribute("p",p1);
RequestDispatcher rd=req.getRequestDispatcher("/display10.jsp");
rd.forward(req,res);
}
}
这是我的豆子
PersonBean.java
public PersonBean()
{
setfn(fn);
setln(ln);
setca(ca);
}
public String getfn()
{
return(fn);
}
public String getln()
{
return(ln);
}
public String getca()
{
return(ca);
}
public void setfn(String newfn)
{
this.fn=newfn;
}
public void setln(String newln)
{
this.ln=newln;
}
public void setca(String newca)
{
this.ca=newca;
}
}
这是我的 Jsp 页面
显示10.jsp
<html>
<head><title></title></head><BR>
<body>
<B>Firstname:<%=p1.fn%></b><BR>
<b>Lastname:<%=p1.ln%></b><BR>
<b>Address:<%=p1.ca%></b><BR>
</body>
</html>
这是我的 Web.xml
web.xml
<description>
Servlet and JSP Examples.
</description>
<display-name>Servlet and JSP Examples</display-name>
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>Process10</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/a</url-pattern>
</servlet-mapping>