Estudiante de Ingeniería en Informática, con proyectos web en desarrollo.
Introduction to the Struts Web Framework
This document takes you through the basics of using NetBeans IDE to develop web applications using the Struts web framework. Struts is an open source framework that extends the Java Servlet API and employs a Model, View, Controller (MVC) architecture. It enables you to createmaintainable, extensible, and flexible web applications based on standard technologies, such as JSP pages, JavaBeans, resource bundles, and XML.
This tutorial teaches you how to build a simple MVC application that displays a login page and returns a success page upon submitting data that passes validation. You learn several basic features provided by Struts, as well as how these features areimplemented using the IDE. Specifically, you use Struts tags in JSP pages, maintain user data with a Struts ActionForm bean, and implement forwarding logic using a Struts Action object. You are also shown how to implement simple validation to your application, including setting up warning message for a failed login attempt.
For a more fine-grained introduction to Struts, see How does Struts work? on theofficial Struts website. Also, make use of the IDE's Javadoc Index Search (Help > Javadoc Index Search) to view the Struts Framework API, which is packaged with the Struts libraries.
• Overview of the Application
• Setting Up a Struts Application
• Creating JSP Pages
o Creating a Login Page
o Creating a Success Page
• Creating an ActionForm Bean
• Creating an Action Class
o Accessing Bean Data and Preparing a Forwarding Condition
o Setting Up an Error Message
• Adding forward Entries to struts-config.xml
• Configuring and Running the Application
o Setting the Welcome Page
o Attaching a Stylesheet
o Running the Application
• See Also
To complete this tutorial, you need the following software and resources.
Software or ResourceVersion Required
Java, version 6.7 or 6.8
Java Development Kit (JDK)
version 5 or 6
GlassFish application server
Tomcat servlet container v2 or v3
• The Web and Java EE installation enables you to optionally install the GlassFish (v2 or v3) application server and the Apache Tomcat servlet container 6.0.18. You must install one of these (orregister a different server in the IDE) to work through this tutorial.
• If you need to compare your project with a working solution, you can download the sample application.
Overview of the Application
When you use Struts, the framework provides you with a controller servlet, ActionServlet, which is defined in the Struts libraries that are included in the IDE, and which is automatically registered inthe web.xml deployment descriptor as shown below. The controller servlet uses a struts-config.xml file to map incoming requests to Struts Action objects, and instantiate any ActionForm objects associated with the action to temporarily store form data. The Action object processes requests using its execute method, while making use of any data stored in the form bean. Once the Action objectprocesses a request, it stores any new data (i.e., in the form bean, or in a separate result bean), and forwards the results to the appropriate view.
Developing a Struts application is similar to developing any other kind of web application in NetBeans IDE. However, you complement your web development toolkit by taking advantage of the Struts support provided by the IDE. For example, you usetemplates in the IDE to create Struts Action objects and ActionForm beans. Upon creation, the IDE automatically registers these classes in the struts-config.xml file and lets you extend this file very easily using menu items in the Source Editor's right-click menu. Because many web applications use JSP pages for the view, Struts also provides custom tag libraries which facilitate interaction with HTML...
Leer documento completo
Regístrate para leer el documento completo.