JSP (10-2)

Source: Internet
Author: User

Once you define this class, compile it and place it in the class path of the network server. This server also needs to define a special directory to place bean classes. If you are using Blazix, you can place them in the "classes" directory. If you must change the class path and the server is running, the network server must be stopped and restarted.

Next let's modify "SaveName. jsp" to use bean to collect data:

<Jsp: useBean id = "user" class = "UserData" scope = "session"/>

<Jsp: setProperty name = "user" property = "*"/>


<HTML>


<BODY>


<A href = "NextPage. jsp"> Continue </A>


</BODY>


</HTML>



Here all we need to do is add a jsp: useBean flag and jsp: setProperty flag. This useBean flag is used to find the "UserData" instance in the session. If an instance is found, it will update the old instance. If the instance is not found, it will create a new UserData instance (the UserData instance is called bean ), then place it in the session. The setProperty flag automatically collects the input data, matches the bean method name, and places the data in the bean.

Next, modify NextPage. jsp to retrieve data from bean:

<Jsp: useBean id = "user" class = "UserData" scope = "session"/>

<HTML>


<BODY>


You entered <BR>


Name: <% = user. getUsername () %> <BR>


Email: <% = user. getEmail () %> <BR>


Age: <% = user. getAge () %> <BR>


</BODY>


</HTML>



Note that the useBean label is reused. This bean is used as a variable of the class "UserData. Data typed by the user is collected in the bean. We can ignore savename.jsp”, and the goal of getname.html is "NextPage. jsp", and the data is equally valid as long as we add a jsp: setProperty flag. In the next tutorial, we will use SaveName. jsp as an error handling and automatically connect to NextPage. jsp. In other words, it will ask the user to correct the error data.

In this tutorial, the secondary exercise is as follows: A) Compile a jsp/HTML file so that you can enter the name of the System property and A System. getProperty value is displayed. B) return to the boolean variable we modified manually. Instead of using the boolean variable, set the variable from the HIDDEN form area to true or false.

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.