BEEHIVE Page Flow Tutorial
1. Development of the development environment [lp1]
1) Download and install Beehive, J2SE5, ANT
1.6.2
Tomcat5
2) Modify BeeHiveUser.cmd under Beehive_Home and run it to set some classpath
3) Add an administrator role in Tomcat (optional)
Catalina_home / conf / tomcat-users.xml
XML Version = '1.0' encoding = 'UTF-8'?>
tomcat-users>
4) Start Tomcat (optional)
% Catalina_home% / bin / startup.bat or
ANT -F% Beehive_Home% / Ant / BuildWebapp.xml Start
2. Simple application development process
1) First ensure the following directory structure, you can copy from / Samples / Netui-Blank.
Resources
WEB-INF
Controller.jpf
Error.jsp
Index.jsp
2) Copy the runtime jars to the corresponding folder and use the ANT command to complete.
ANT -F% Beehive_Home% / Ant / BuildWebapp.xml -dwebapp.dir =
Note: The name of the folder and files cannot have symbols other than alphanumeric underscores, such as "-".
3) Create a JSP file and JPF file.
4) Compile and configure Page Flow to ensure that Tomcat is already started. WebApp-Blank is a WebApp name, and
ANT -F% Beehive_Home% / Ant / BuildWebapp.xml -dwebapp.dir =
Note: If you throw a Context Path Already Exists error, use the ANT command first Undeploy Application. Then use the above command to recompile and configure it. ANT -F% Beehive_Home% / Ant / BuildWebapp.xml -dwebapp.dir =
5) Re-build and configure it after the JPF is modified.
ANT -F% Beehive_Home% / Ant / BuildWebapp.xml -dwebapp.dir =
3. Data Submit
1) JSP file, add:
name:
age:
netui: form>
p>
2) Represents the Java class submitting the form
Create a Java class that represents the submit form. When the data is submitted, the class is instantiated, and the form data is loaded into the member of the class.
You can put it under / web-inf / src / forms.
Package Forms;
Public Class Profileform
{
PRIVATE INT AGE;
PRIVATE STRING NAME;
Public void setname (String name)
{
THIS.NAME = Name;
}
Public string getName ()
{
Return this.name;
}
Public void setage (int Age)
{
THIS.AGE = AGE;
}
Public int getage ()
{
Return this.Age;
}
}
3) JPF file, modified as follows:
Import Org.apache.beehive.Netui.pageFlow.Forward;
Import org.apache.beehive.netui.pageflow.pageflowController;
Import org.apache.beehive.netui.pageflow.annotations.jpf;
Import Forms.profileform;
@ JPF.Controller
Public Class Controller Extends PageFlowController
{
@ JPF.Action
FORWARDS = {
@ JPF.Forward (name = "success", Path = "index.jsp")
}
)
Public Forward Begin ()
{
Return New Forward ("Success");
}
@ JPF.Action
FORWARDS = {
@ JPF.Forward (name = "success", Path = "Page2.jsp")}
)
Public Forward Topage2 ()
{
Return New Forward ("Success");
}
@ JPF.Action
FORWARDS = {
@ JPF.Forward (name = "success", Path = "Page2.jsp")
}
)
Public Forward ProcessData (Profileform Form)
{
System.out.println ("Name:" form.getname ());
System.out.println ("Age:" form.getage ());
Return New Forward ("Success");
}
}
4. Data display
1) JSP file
<% @ page language = "java" contenttype = "text / html; charSet = UTF-8"%>
<% @ Taglib Uri = "http://beehive.apache.org/netui/tags-html-1.0" prefix = "Netui"%>
hEAD>
name:
age:
NetUI: Body>
netui: html>
2) JPF file
@ JPF.Action
FORWARDS = {
@ JPF.Forward (Name = "Success", Path = "DisplayData.jsp")
}
)
Public Forward ProcessData (Profileform Form)
{
System.out.println ("Name:" form.getname ());
System.out.println ("Age:" form.getage ());
GetRequest (). SetAttribute ("Data", Form);
Return New Forward ("Success");
}
5. Database control
1) Insert
@SQL (statement = "INSERT INTO EMPLOYEE"
(ID, FNAME, LNAME, TITLE)
"VALUES ({Emp.id}, {Emp.FName}, {Emp.Title})")
Public void insertemployee (Employee EMP) THROWS SQLEXCEPTION;
Note: Variable name sensation sensitive
2) query. Note If returns to integer, be sure to return to Integer, not int.
l Returns a value. Title's VARCHAR type determines how to return to String
@SQL (statement = "SELECT TIOM EMPLOYEE WHERE ID = {id})
Public String GetEmployeetitle (Int ID) THROWS SQLEXCEPTION;
l Returns a record. The return type can be a user-defined object (as EMPLOYEE below), or a java.util.hashmap object. If the former, the user-defined object must contain all column, and ensure that the variable names of the two correspondence.
@SQL (statement = "select * from Employee where id = {id}")
Public Employee FindemPloyee (Int ID) throws SqlexCeption;
Public Class Employee
{
Public int ID;
Public String Fname;
Public String Lname;
Public String Title;
}
l Returns multiple records. The return type can be an array, or java.util.ITerator, or java.sql.resultset. If it is Iterator, it must define IteRaulementType. MaxRows defines the number of records returned up to.
@SQL (statement = "select * from employee order by lname", ituteElelementType = Employee.class, maxRows = 500)
Public iterator getEmployeessORTEDBYLASTNAME () THROWS SQLEXCEPTION;
3) Data control defines two Annotation: SQL and ConnectionDataSource.
l SQL Annotation defines query statements and related properties. If you return multiple records, you need to define iterateorelementType.
Public @Interface SQL
{
String statement () Default "";
Int maxrows () default maxrows_all;
@ AnnotationMembertypes.Option
Class iteratorelementType () default undefinedItemType.class;
}
l ConnectionDataSource Annotation Defines the data source for data control to get the connection.
Public @Interface ConnectionDataSource
{
String Jndiname (); // no default ... Value Is Required
}