Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How does a servlet communicate with a JSP page?
How does a servlet communicate with a JSP page?
✍: Guest
The following code snippet shows how a servlet instantiates a bean and initializes it with FORM data posted by a browser. The bean is then placed into the request, and the call is then forwarded to the JSP page, Bean1.jsp, by means of a request dispatcher for downstream processing.
public void doPost (HttpServletRequest request,
HttpServletResponse response)
{
try {
govi.FormBean f = new govi.FormBean();
String id = request.getParameter("id");
f.setName(request.getParameter("name"));
f.setAddr(request.getParameter("addr"));
f.setAge(request.getParameter("age"));
//use the id to compute
//additional bean properties like info
//maybe perform a db query, etc.
// . . .
f.setPersonalizationInfo(info);
request.setAttribute("fBean",f);
getServletConfig().getServletContext().
getRequestDispatcher
("/jsp/Bean1.jsp").forward(request, response);
} catch (Exception ex) {
. . .
}
}
The JSP page Bean1.jsp can then process fBean, a
fter first extracting it from the default request
scope via the useBean action.
jsp:useBean id="fBean" class="govi.FormBean"
scope="request"/ jsp:getProperty
name="fBean" property="name" /
jsp:getProperty name="fBean" property="addr"
/ jsp:getProperty name="fBean"
property="age" / jsp:getProperty name="fBean"
property="personalizationInfo" /
2013-08-01, 2321👍, 0💬
Popular Posts:
.NET INTERVIEW QUESTIONS - Where do you specify session state mode in ASP.NET ? The following code e...
What will be printed as the resultof the operation below: int x; int modifyvalue() { return(x+=10); ...
What are secure and non-secure websites? A secure Website uses the Secure Socket Layer (SSL) protoco...
From performance point of view how do they rate ? Repeater is fastest followed by Datalist and final...
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters? Unicode requires 1...