advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Building a sample Web App with STRUTS :

6. Let us compile this java file. First let us set a parameter in NetBeans - to set target directory where the java files will be compiled (classes will be stored). Go to tools - options compiler types- external compilation (the external compiler, javac is typically the default compiler. Set the target directory to StrutsNetBeansSample /WEB-INF/classes. Click on the file (TestFormBean.java) in the explorer window and click build - > compile from main menu. The o/p window should show a message like 'Finished TestFormBean. Now we have a form bean we need an Action class that will take this form bean - use the ipString entered by user to pass to the next page.

7. Lets create the TestActionHandler.java under src/com/openstack/struts/testapp. Here is the class definition:



package com.openstack.struts.testapp;


import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;

import com.openstack.struts.testapp.*;

public final class TestActionHandler extends Action {

  public ActionForward perform(ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
throws IOException, ServletException {


	
       
     TestFormBean tform = 
(com.openstack.struts.testapp.TestFormBean) form; String tmpStr = "Welcome " + tform.getIpString() + " !"; tform.setIpString(tmpStr); request.setAttribute("TestFormBean", tform); return (mapping.findForward("success")); } }
As you can see all we are doing is taking the ipString (where user will enter his / her name) and then generating a welcome message. Then we reset the ipString with this complete message and set the bean back in the request object. Finally we forward the control to the 'success' handler of this action.

Look at the 'perform' method. It returns 'ActionForward' that forwards the action to the next page (or handler).

The part 'return (mapping.findForward("success"))' will instruct struts to go to next step.

Let"s look at how we specify this 'next step' in struts: Open the struts.config from the WEB-INF directory. Look at the action mapping:


  <action    path="/TestAction"
           type="com.openstack.struts.testapp.TestActionHandler"
           name="TestFormBean"
           scope="request"
           validate="false">
      <forward name="success"     path="/TestResult.jsp" />
    </action>



The TestAction (from the TestFormPage.jsp) maps to TestActionHandler class under com.openstack.struts.testapp. In our TestFormPage.JSP we have specified the submit action in the form as "TestAction". So when the form submits STRUTS will read this file to evaluate 'TestAction' and call the perform method in:
com.openstack.struts.testapp.TestActionHandler Class.
Finally the mapping.findForward("success")) will forward the request to TestResult.jsp, based on the following line in struts.config
 <forward name="success"
path="/TestResult.jsp" /> 
So, in summary STRUTS will do the following tasks:
  • Copy user entered values into a form bean.
  • Call the action handler passing the form bean.
  • Facilitate screen flow using the action mapping.

[Next]

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs