java pattern(shine enterprise patern)
Maplet (Web, MVC Framework)
What is Maplet?
Maplet is a framework for implementing web based program, which is compatible with MVC architecture. This framework is very easy and helpful for developers and analyzers to do their jobs better than before, let’s begin with a simple example.
First example
First you have to download shine library from one of these web sites:
www.j2os.org
Shine-Enterprise-Java-Pattern | Download Shine-Enterprise-Java-Pattern software for free at SourceForge.net
(file) maplet.tld
///////////////////
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "
http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>maplet</shortname>
<tag>
<name>Service</name>
<tagclass>org.j2os.shine.maplet.tag.Service</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>name</name>
</attribute>
</tag>
<tag>
<name>SecureService</name>
<tagclass>org.j2os.shine.maplet.tag.SecureService</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>name</name>
</attribute>
</tag>
<tag>
<name>ErrorService</name>
<tagclass>org.j2os.shine.maplet.tag.ErrorService</tagclass>
<bodycontent>JSP</bodycontent>
</tag>
</taglib>
////////////////////////
request page
(file) AddEmail.jsp
////////////////////////
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
</head>
<body>
<DIV align="center">
<P> </P>
<P>
<STRONG><FONT size="5">Add a new Email to my email list</FONT></STRONG>
</P>
<P> </P>
<P> </P>
<form action="../../servlet/Model.Controller" method="get">
<DIV align="left">
<P>Name:
<input type="text" name="name"/>
</P>
<P>Email:
<input type="text" name="email"/></P>
<P>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</P>
</DIV>
</form>
</DIV>
</body>
</html>
///////////////////
request page
(file) SearchEmail.jsp
/////////////////////////
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
</head>
<body>
<P> </P>
<P align="center">
<STRONG><FONT size="5">Search an email in my list</FONT></STRONG>
</P>
<P> </P>
<form action="../../servlet/Model.Controller" method="get">
<P>Name:
<input type="text" name="name"/>
</P>
<P>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</P>
</form>
</body>
</html>
/////////////////////////
request page
(file) AddPhoneNumber.jsp
////////////////////////////
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
</head>
<body>
<DIV align="center">
<P> </P>
<P>
<STRONG><FONT size="5">Add a new phone to my phone book</FONT></STRONG>
</P>
<P> </P>
<P> </P>
<form action="../../servlet/Model.Controller" method="get">
<DIV align="left">
<P>Name:
<input type="text" name="name"/>
</P>
<P>phone num:
<input type="text" name="ph_num"/></P>
<P>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</P>
</DIV>
</form>
</DIV>
</body>
</html>
////////////////////
request page
(file) SearchPhoneNumber.jsp
////////////////////////////
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
</head>
<body>
<P> </P>
<P align="center">
<STRONG><FONT size="5">Search a phone number in my phone book</FONT></STRONG>
</P>
<P> </P>
<form action="../../servlet/Model.Controller" method="get">
<P>Name:
<input type="text" name="name"/>
</P>
<P>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</P>
</form>
</body>
</html>
////////////////
response page
(file) EmailServiceResponses.jsp
//////////////////////////////////////
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="/WEB-INF/maplet.tld" prefix="maplet"%>
<maplet:Service name="add_success">Your email address had entered successfully.<br/>name:<br/><%=request.getParameter("name")%><br/>email:<br/><%=request.getParameter("email")%> </maplet:Service>
<maplet:Service name="search_success"><%=request.getParameter("name")%>'s email : <%=request.getParameter("email")%></maplet:Service>
<maplet:Service name="add_error">your email address failed! there was a problem!</maplet:Service>
<maplet:Service name="search_error">you had entered a wrong value!</maplet:Service>
<maplet:ErrorService>No Access!</maplet:ErrorService>
///////////////////////////////////////////////////////////
response page
(file) PhoneServiceResponses.jsp
/////////////////////////////////////
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="/WEB-INF/maplet.tld" prefix="maplet"%>
<maplet:Service name="add_success">Your phone number had entered successfully.<br/>name:<br/><%=request.getParameter("name")%><br/>phone:<br/><%=request.getParameter("ph_num")%> </maplet:Service>
<maplet:Service name="search_success"><%=request.getParameter("name")%>'s phone : <%=request.getParameter("ph_num")%></maplet:Service>
<maplet:Service name="add_error">your number failed! there was a problem!</maplet:Service>
<maplet:Service name="search_error">you had entered a wrong value!</maplet:Service>
<maplet:ErrorService>No Access!</maplet:ErrorService>
///////////////////////////////////
engine page (maplet)
(file) Controller.java
/////////////////////////////////
package Model;
import org.j2os.shine.maplet.*;
import org.j2os.shine.jconnection.JDBC;
import java.sql.*;
public class Controller extends Maplet {
public String name;
public String email;
public String ph_num;
private String forward_tag,forward_page;
JDBC db=new JDBC();
public void initialize() throws Exception{
db.login("com.mysql.jdbc.Driver","jdbc:mysql://localhost/j2os", "Username", "pass", true);
}
public void addEmail() throws Exception {
boolean a=db.executeSQLQuery("insert into email_table (name,email) values ('"+name+"','"+email+"')");
forward_page="../service/EmailServiceResponses.jsp";
if (a) {
forward_tag = "add_success";
} else {
forward_tag = "add_error";
}
}
public void searchEmail() throws Exception {
ResultSet r = db.getSQLQueryContent("select email from email_table where name like '"+name+"'");
while (r.next()) {
email= r.getString("email");
}
addURL("email",email);
forward_page="../service/EmailServiceResponses.jsp";
if (!(email.equals(""))) {
forward_tag = "search_success";
} else {
forward_tag = "search_error";
}
}
public void addPhoneNumber() throws Exception {
boolean a=db.executeSQLQuery("insert into phon_table (name,phone) values ('"+name+"','"+ph_num+"')");
forward_page="../service/PhoneServiceResponses.jsp";
if (a) {
forward_tag = "add_success";
} else {
forward_tag = "add_error";
}
}
public void searchPhoneNumber() throws Exception {
ResultSet r = db.getSQLQueryContent("select phone from phone_table where name like '"+name+"'");
while (r.next())
{
ph_num= r.getString("phone");
}
addURL("ph_num",ph_num);
forward_page="../service/PhoneServiceResponses.jsp";
if (!(ph_num.equals("")))
{
forward_tag = "search_success";
} else {
forward_tag = "search_error";
}
}
public void rater() throws Exception {
db.commit();
forward(forward_page, forward_tag);
}
}
//////////////////////////////////////////////////////