Communication between the servlet and the JSP

Source: Internet
Author: User
Js|servlet The following code fragment demonstrates a servlet that illustrates (instantiates) a bean and initializes it with the form data sent by the browser. The bean is then added to the request, which is sent to the JSP page (bean1.jsp), which is obtained through the request and processed further.

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) {
. . .
}
}

When it is first executed from the default request range of the Usebean operation, that is, the Fbean can be processed in the bean1.jsp of the JSP file.

<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"/>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.