xiaoxing tech

July 25, 2007

JSP day 2, Using Netbeans 5.5.1

Filed under: JSP — xiaoxing @ 9:21 am

1. Create a new Web Application: “PCSWebUpdater”, the Context Path is /PCSWebUpdater. Version: J2EE 1.4
2. Source structure: Java BluePrints
3. Server: Bundled Tomcat 5.5.17
4. Click “Finish”.
5. index.jsp is opened in the source file editor.
6. Add a Java Class: “Handler” into
Source Packages. Package: “me”.
7. Handler.java is opened in the source file editor.
8. Writing code. Remember, to generate Getter and Setter Methods, you need to do:
Right-click the word name in the field
declaration at the start of the class and choose Refactor > Encapsulate Fields.
Click Next to run the command with its default options. Click Do Refactoring.
9. Open index.jsp file in editor.
10. In the Palette on the right side of the Source Editor, expand HTML Forms and
drag a Form item below the <h1> tags in the Source Editor.
11. “Insert Form” window appears.
12.
Set the following values:

  • Action: response.jsp
  • Method: GET
  • Name: Name Input Form

Click OK. The Form is added to the index.jsp file.
13. Drag a Text Input item to just before the </form> tag.

Set the following values:

  • Name: name
  • Type: text

Click OK. The Text Input is added between the <form> tags.
14. Drag a Button item to just before the </form> tag.

Set the following values:

  • Label: OK
  • Type: submit

Click OK. The Button is added between the <form> tags.
15. Type Enter your name: in front of the first <input> tag and change the text between the
<h1> tags to Entry Form.
16. Creating response.jsp (New > JSP in Web Pages node)
17. In the Palette on the right side of the Source Editor, expand JSP and
drag a Use Bean item right below the <body> tag in the Source Editor.

Set the following values:

  • ID: mybean
  • Class: org.me.hello.NameHandler
  • Scope: session

Click OK. The Use Bean is added below the <body> tag.
18. Add a Get Bean Property item and a Set Bean Property item from the Palette. Then
change the code so that the tags between the <body> tags look as follows:

<jsp:useBean id="mybean" scope="session" class="org.me.hello.NameHandler" /><jsp:setProperty name="mybean" property="*" /><h1>Hello, <jsp:getProperty name="mybean" property="name" />!</h1>

***************************************************************************************************



Ready to run. Input your name......

Powered by ScribeFire.

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.