This essay developed out of conversations I've had with several other programmers about why Java smelled suspicious. It's not a critique of Java!
Sycorax - complete tutorials
Programming Tutorials
" Java provides the industry - software companies and customer alike , an opportunity to create a true open computing environment where software is portable,
and customers benefit from increase competition. "
Java and the Future
December 1, 2008-LEJB 3.1: EJB New and Improved!
The EJB 3.0 specification was a huge improvement from what you were used to in the early versions of EJB. Available as an early draft, EJB 3.1 has many more features and is even easier to use.
December 1, 2008-Should Java Assert that Network I/O Can't Occur on the UI Thread?
Doing network I/O on the user interface (UI) thread is bad. Most developers know that and can tell you why; unfortunately, it's still done.
Register now to recieve special alert and latest technology news!
IDE - NetBeans
Application Server
Jboss 3.2.5
You can also use Tomcat.
DynaActionForm class
A form bean of type Typ DynaActionForm is defined in the struts config file. The actual class is created by Struts dynamically. You define all attributes of the class in the Struts config file.
Example for a DynaActionForm definition in the Struts config file:
<form-beans>
<form-bean name="myDynaForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="age" type="java.lang.Integer" />
<form-property name="name" type="java.lang.String" />
</form-bean>
The form bean can be used in an Struts action. Below there is an example of an ActionMapping using our form bean.
Example:
<action input="/"
name="myDynaForm" path="/Dyna"
scope="session"
type="com.sycorax.tutorial.dynaaction.DynaStrutsAction"/>
Create the Action class
Create the class DynaStrutsAction in the package com.sycorax.tutorial.dynaaction.
The class extends the class Action.
Implement the method execute(..).
Output the name and the age to the log.
The complete source code is shown below.
public class DynaStrutsAction extends Action {public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
//Cast DynaActionForm
DynaActionForm dyForm = (DynaActionForm) form;
//Access the properties of the DynaActionForm
System.out.println(dyForm.get("name"));
System.out.println(dyForm.get("age"));
return mapping.findForward("success");
}
}
Create a JSP file
Create a JSP test.jsp
Below you can see the source code of the JSP file.
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<html:html locale="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message key="welcome.title"/></title>
<html:base/>
</head>
<body style="background-color: white">
<h3><bean:message key="welcome.heading"/></h3>
<p><bean:message key="welcome.message"/></p>
<html:form action="/Dyna">
<html:errors />
Name: <html:text property="name" /> <br>
Age: <html:text property="age" /> <br>
<html:submit />
</html:form>
</body>
</html:html>
Configure the Action (struts-config.xml)
Add an action mapping in the struts-config.xml. Add the form bean myDynaForm to the action and create a forward to the test.jsp.
name specifies the action of the form bean.
Type is the path to our action class, ExampleAction.
<forward ...> is the forward to our test.jsp.
<action-mappings>
<action input="/"
name="myDynaForm" path="/Dyna"
scope="session"
type="com.sycorax.tutorial.dynaaction.DynaStrutsAction"/>
</action-mappings>
Test your example
We have finished our example application. Test the example by calling
http://localhost:8080/DynaActionFormEx/test.jsp
(We expect a standardinstallation of JBOSS or Tomcat)