Beruflich Dokumente
Kultur Dokumente
NetBeans IDE
HOME / Docs & Support
NetBeans Platform
Plugins
Community
Partners
Search
Training
Java Programming Language
Support
Oracle Development Tools Support Offering for NetBeans IDE
Documentation
General Java Development External Tools and Services Java GUI Applications Java EE & Java Web Development Web Services Applications NetBeans Platform (RCP) and Module Development PHP Applications C/C++ Applications Mobile Applications Sample Applications Demos and Screencasts
GlassFish Server Open Source Edition 3.x or Tomcat servlet container or Oracle Web Logic server Notes: The Java EE installation (not Java SE!) enables you to optionally install the GlassFish server and the Apache Tomcat servlet container. If you need to compare your project with a working solution, you can download the sample application. 11gR1 (10.3.3) or later version 6.x (EE 5) or 7.x ((EE 5 or EE 6)
More
FAQs Contribute Documentation! Docs for Earlier Releases
$ P R O J E C T H O M E .
4. (Optional) Select the Use Dedicated Folder for Storing Libraries checkbox and specify the location for the libraries folder. See Sharing Project Libraries for more information on this option. 5. Click Next. The Server and Settings panel opens. Select the version of Java EE you want to use with your application. 6. Select the server to which you want to deploy your application. Only servers that are registered with the IDE are listed. Note that the Context Path (i.e., on the server) becomes / H e l l o W e b , which is based on the name you gave the project in a previous step. 7. Click Finish. The IDE creates the $ P R O J E C T H O M E / H e l l o W e bproject folder. You can view the project's file structure in the Files window (Ctrl2), and its logical structure in the Projects window (Ctrl-1).
The project folder contains all of your sources and project metadata, such as the project's Ant build script. The HelloWeb project opens in the IDE. The welcome page, i n d e x . j s p , opens in the Source Editor in the main window.
https://netbeans.org/kb/docs/web/quickstart-webapps.html
1/6
4/2/13
S t r i n gn a m e ;
4. Add the following constructor to the class:
p u b l i cN a m e H a n d l e r ( ){}
5. Add the following line in the N a m e H a n d l e r ( )constructor:
n a m e=n u l l ;
2. Click Refactor. Getter and setter methods are generated for the n a m efield. The modifier for the class variable is set to p r i v a t ewhile getter and setter methods are generated with public modifiers. The Java class should now look similar to the following.
p a c k a g eo r g . m y p a c k a g e . h e l l o ; / * * * *@ a u t h o rn b u s e r * / p u b l i cc l a s sN a m e H a n d l e r{ p r i v a t eS t r i n gn a m e ; / * *C r e a t e san e wi n s t a n c eo fN a m e H a n d l e r* / p u b l i cN a m e H a n d l e r ( ){ n a m e=n u l l ;
https://netbeans.org/kb/docs/web/quickstart-webapps.html
2/6
4/2/13
}
p u b l i cS t r i n gg e t N a m e ( ){ r e t u r nn a m e ; } p u b l i cv o i ds e t N a m e ( S t r i n gn a m e ){ t h i s . n a m e=n a m e ; } }
4. Drag a Text Input item to a point just before the < / f o r m >tag, then specify the following values: Name: name Type: text Click OK. An HTML < i n p u t >tag is added between the < f o r m >tags. Delete the v a l u eattribute from this tag. 5. Drag a Button item to a point just before the < / f o r m >tag. Specify the following values: Label: OK Type: submit Click OK. An HTML button is added between the < f o r m >tags. 6. Type E n t e ry o u rn a m e :just before the first < i n p u t >tag, then change the default H e l l oW o r l d !text between the < h 1 > tags to E n t r yF o r m . 7. Right-click within the Source Editor and choose Format (Alt-Shift-F) to tidy the format of your code. Your i n d e x . j s pfile should now appear similar to the following:
< h t m l > < h e a d > < m e t ah t t p e q u i v = " C o n t e n t T y p e "c o n t e n t = " t e x t / h t m l ;c h a r s e t = U T F 8 " > < t i t l e > J S PP a g e < / t i t l e > < / h e a d > < b o d y > < h 1 > E n t r yF o r m < / h 1 > < f o r mn a m e = " N a m eI n p u tF o r m "a c t i o n = " r e s p o n s e . j s p " > E n t e ry o u rn a m e : < i n p u tt y p e = " t e x t "n a m e = " n a m e "/ > < i n p u tt y p e = " s u b m i t "v a l u e = " O K "/ > < / f o r m > < / b o d y > < / h t m l >
https://netbeans.org/kb/docs/web/quickstart-webapps.html
3/6
4/2/13
ID: mybean Class: org.mypackage.hello.NameHandler Scope: session Click OK. Notice that the < j s p : u s e B e a n >tag is added beneath the < b o d y >tag. 3. Drag a Set Bean Property item from the Palette to a point just before the < h 1 >tag and click OK. In the < j s p : s e t P r o p e r t y > tag that appears, delete the empty v a l u eattribute and edit as follows. Delete the v a l u e=" "attribute if the IDE created it! Otherwise, it overwrites the value for n a m ethat you pass in i n d e x . j s p .
r e s p o n s e . j s pfile should now appear similar to the following: < b o d y > < j s p : u s e B e a ni d = " m y b e a n "s c o p e = " s e s s i o n "c l a s s = " o r g . m y p a c k a g e . h e l l o . N a m e H a n d l e r " / > < j s p : s e t P r o p e r t yn a m e = " m y b e a n "p r o p e r t y = " n a m e "/ > < h 1 > H e l l o ,< j s p : g e t P r o p e r t yn a m e = " m y b e a n "p r o p e r t y = " n a m e "/ > ! < / h 1 > < / b o d y >
https://netbeans.org/kb/docs/web/quickstart-webapps.html
4/6
4/2/13
2. The IDE opens an output window that shows the progress of running the application. Look at the HelloWeb tab in the Output window. In this tab, you can follow all the steps that the IDE performs. If there is a problem, the IDE displays error information in this window.
3. The IDE opens an output window showing the server status. Look at the tab in the Output window with the name of your server. Important: If the GlassFish server fails to start, start it manually and run the project again. You can start the server manually from the Services window, by right-clicking the server node and selecting Start. The server output window is very informative about problems running Web applications. The server's logs can also be helpful. They are located in the server's relevant domain directory. You can also view the IDE log, visible by selecting View > IDE log.
4. The i n d e x . j s ppage opens in your default browser. Note that the browser window may open before the IDE displays the server output.
5. Enter your name in the text box, then click OK. The r e s p o n s e . j s ppage displays, providing you with a simple greeting.
Troubleshooting
I've b uilt and run the project. When I click the OK b utton for i n d e x . j s p , an error page displays indicating that r e s p o n s e . j s pis not availab le. Have you looked in the IDE's Output window (Ctrl-4) in the project tab or in the server tab? What error messages are there? What JDK does your project use? What server? JDK 7 requires GlassFish 3.x or Tomcat 7.x. Right-click the project's node in the Projects window and select Properties. The JDK is in the Libraries category, in the Java Platform field. The server version is in the Run category. Lastly, download the sample project and compare it with your own. I've b uilt and run the project b ut no name appears, only "Hello, !" Does your <jsp:setProperty> tag contain a v a l u e=" "attribute? This overwrites the value you passed in the i n d e x . j s pform and replaces it with an empty string. Delete the v a l u eattribute. I've b uilt and run the project b ut get "Hello, null!" First, check the IDE's Output windows for both application and server, and the server log. Is the server running? Was the application deployed? If the server is running and the application was deployed, are you getting an
https://netbeans.org/kb/docs/web/quickstart-webapps.html
5/6
4/2/13
See Also
This concludes the Introduction to Developing Web Applications tutorial. This document demonstrated how to create a simple web application using NetBeans IDE, deploy it to a server, and view its presentation in a browser. It also showed how to use JavaServer Pages and JavaBeans in your application to collect, persist, and output user data. For related and more advanced information about developing web applications in NetBeans IDE, see the following resources: Introduction to the Struts Web Framework. Describes the basics of using NetBeans IDE to develop web applications using the Struts framework. Java EE & Java Web Learning Trail
SiteMap
About Us
Contact
By use of this w ebsite, you agree to the NetBeans Policies and Terms of Use. 2012, Oracle Corporation and/or its affiliates. Sponsored by
https://netbeans.org/kb/docs/web/quickstart-webapps.html
6/6