SlideShare a Scribd company logo
1 of 43
 
[object Object],[object Object],Rapid Application Development Frameworks
Rapid Application Development Frameworks ,[object Object],[object Object],[object Object],[object Object],[object Object]
Architecture of Frameworks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Top Open Source Web Frameworks in Java
MVC (Model-View-Controller) Architecture MODEL … how the underlying data is structured  (Enterprise Data + Business Rules) VIEW … presentation to the user/client  (User Interface Element) CONTROLLER … receives input from user and take appropriate action … element that performs the processing … manage the request of the web browser
MVC-1 Vs. MVC-2 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Programmers develop web applications and implement their SQL Queries with the business logics directly in the HTML document. <html><head><title>Important title</title></head><body> <someScript> dbConnection = openDBConnection(someDB) resultSet = dbConnection.executeQuery('select bookName from books') loop over resultSet{ print (resultSet.field('bookName') + '<br>') } </someScript> </body></html>   Convenient for small projects only For large scale projects… need of separation
<html:form action=&quot;someAction&quot;> Please give your name and the book title <br> Name: <html:text property=&quot;name&quot;/> <br> Title: <html:text property=&quot;title&quot;/> <br> <html:submit/> </html:form> Struts support resources files. In this files you can define a key for a text. bookDialog.formIntro=Please give your name and the title of the book. bookDialog.inputName=Name: bookDialog.bookTitle=Title: This key can be used to diplay the text in the JSP file. <html:form action=&quot;someAction&quot;> <bean:message key=&quot;bookDialog.formIntro&quot;/> <br> <bean:message key=&quot;bookDialog.inputName&quot;/> <html:text property=&quot;name&quot;/> <br> <bean:message key=&quot;bookDialog.bookTitle&quot;/> <html:text property=&quot;title&quot;/> <br> <html:submit/> </html:form>
<html:form action=&quot;someAction&quot;> Please give your name and the book title <br> Name: <html:text property=&quot;name&quot;/> <br> Title: <html:text property=&quot;title&quot;/> <br> <html:submit/> </html:form> Struts support resources files. In this files you can define a key for a text. bookDialog.formIntro=Please give your name and the title of the book. bookDialog.inputName=Name: bookDialog.bookTitle=Title: This key can be used to diplay the text in the JSP file. <html:form action=&quot;someAction&quot;> <bean:message key=&quot;bookDialog.formIntro&quot;/> <br> <bean:message key=&quot;bookDialog.inputName&quot;/> <html:text property=&quot;name&quot;/> <br> <bean:message key=&quot;bookDialog.bookTitle&quot;/> <html:text property=&quot;title&quot;/> <br> <html:submit/> </html:form>
Setting Up Development Environment Installing JDK: Download JDK latest. Follow the instruction given in the installation manual and install JDK. Installing Tomcat: Download Tomcat from the apache site and install it. To  test your installation go to your installation  directory/bin  and issue startup command to run the server. Open  browser  and type  http://localhost:8080/  to test the  Server . It should display the welcome page.
Installing Struts Application Download latest version of Struts from the official site of Struts  http:// jakarta.apache.org /struts .   Extract the file into your favorite directory and copy  struts-blank.war ,  struts-documentation.war  and  struts-example.war  from &quot; jakarta-struts-1.1ebapps &quot; directory into &quot; jakarta-tomcat-5.0.4ebapps &quot; directory.  struts-blank.war  is the blank struts application which is useful in creating struts application from scratch. Use this file to create new web application. struts-documentation.war  contains API and important documents for the struts application development. struts-example.war  is simple MailReader Demonstration Application.
MyApplication           |      ----src     // Java Source Code folder ----WEB-INF //within folder                |      ---------web.xml //file    ---------struts-config.xml //file    ---------struts-bean.tld //file    ---------struts-html.tld //file    ---------struts-logic.tld //file    ---------struts-nested.tld //file    ---------struts-template.tld //file    ---------struts-tiles.tld //file    ---------classes //folder    ---------lib //within folder   
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Developing First Struts Application … Rename struts-blank.war  to struts-tutorial.war from jakarta-tomcat-5.0.4ebapps and copy it to the &quot;jakarta-tomcat-5.0.4ebapps&quot; directory. Tomcat automatically extracts the file and loads the application.
Extracting the content Now you can use the winzip to extract the content of struts-2.1.8.1-all.zip file. After extracting the file you will get following files/Directories:
Extracting the content The  apps  directory contains: a) struts2-blank-2.1.8.1.war  - Blank Struts 2.1.8 application, can use used to start the blank application b) struts2-mailreader-2.1.8.1.war  - Struts 2.1.8 mail reader application demo c) struts2-portlet-2.1.8.1.war  - Struts 2.1.8 portlet application d) struts2-rest-showcase-2.1.8.1.war  - Example to use the REST (Representational State Transfer) services e) struts2-showcase-2.1.8.1.war  - Struts 2.1.8 showcase applications. Other directories are docs, lib and src.
Set-up
Then run the tomcat and type  http://localhost:8080/struts2-blank-2.1.8.1  in the  browser . It should display the &quot;Struts is up and running ...&quot; message on the browser.
Struts Showcase Example Copy the struts2-showcase-2.1.8.1.war file into webapps directory of Tomcat and then start the Tomcat.
Struts Showcase Example … Now open the  browser  and type  http://localhost:8080/struts2-showcase-2.1.8.1/ . Your browser should display the showcase application's home page.
Struts Showcase Example … The showcase application provides following examples: Ajax  Ajax Chat  Action Chaining  Config Browser  Conversion  CRUD  Execute & Wait  File Download  File Upload  FreemarkerHangman  JavaServer   Faces  Tags  Tiles  Token Validation  Interactive Demo  Person Manager  Struts 1 Integration
Screenshot of the Chat application
Developing a Test Application - Display Message Web configuration file web.xml …  To configure the Struts filter <filter>       <filter-name>struts2</filter-name>  <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> …  then configure the filter mapping for struts2 filter:   <filter-mapping>       <filter-name>struts2</filter-name>      <url-pattern>/*</url-pattern> </filter-mapping>
FILTERS FOR SECURITY In the web.xml file, you can specify the filter name and class, and initialization parameters. Then, associate the filter with a URL pattern in a filter mapping.   <filter>   <filter-name>adminAccessFilter</filter-name>   <filter-class>      com.jamesholmes.minihr.security.AuthorizationFilter     </filter-class>   <init-param>     <param-name>roles</param-name>     <param-value>administrator</param-value>   </init-param>   <init-param>     <param-name>onError</param-name>     <param-value>/index.jsp</param-value>   </init-param> </filter> <filter-mapping>   <filter-name>adminAccessFilter</filter-name>   <url-pattern>/admin/*</url-pattern> </filter-mapping> The filter provides a basic security  mechanism for a firewall to determining what traffic passes through the firewall based on IP address details. Example –  To restrict IP Addresses
public class  IPFilterExample  implements  Filter{    public  IPFilterExample() {}    public final static  String IP = &quot;193.168.10.146&quot;;    private  FilterConfig filterConfig;       public void  init(FilterConfig config)  throws  ServletException{      this .filterConfig = config;   }    public void  doFilter(ServletRequest request, ServletResponse response,     FilterChain filterchain)  throws  IOException, ServletException {     response.setContentType(&quot;text/html&quot;);     PrintWriter out = response.getWriter();     out.println(&quot;<html><head><title>IP Filter Example</title></head>&quot;);     String userip = request.getRemoteAddr();     HttpServletResponse httpResponse =  null ;      if  (response  instanceof  HttpServletResponse){       httpResponse = (HttpServletResponse) response;     }      if  (IP.equals(userip)) {       httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN,&quot;You are not         allowed to access the servlet!&quot;);           }  else  {       filterchain.doFilter(request, response);       out.println(&quot;<body><h3><font color='green'>Passed successfully from IP       Filter<font></h3></body></html>&quot;);     }   }    public void  destroy() {} }  IP FILTER
MOVING BACK TO OUR TEST APPLICATION -  WEB.XML file <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <web-app id=&quot;WebApp_9&quot; version=&quot;2.4&quot; xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;> <display-name>My Application Struts 2.8.1 Tutorials</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
WRITING THE ACTION CLASS -  HelloWorld.java import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport {     public String execute() throws Exception {         setMessage(getText(MESSAGE));         return SUCCESS;     }     public static final String MESSAGE = &quot;HelloWorld.message&quot;;     private String message;     public String getMessage() {         return message;     }     public void setMessage(String message) {         this.message = message;     } }
HelloWorld.java The class extends  com.opensymphony.xwork2.ActionSupport  class. It provides a method  getText(),  to retrieve the message for the current local from the message resource file. The Struts framework executes the following default method :      public  String execute()  throws  Exception {         setMessage(getText(MESSAGE));          return  SUCCESS;     } This method is just setting the message and the returning the SUCCESS value, which is the result of the action.
HelloWorld.java in Struts In this example HelloWorld.jsp is rendered and displayed to the user.  Configuration of the HelloWorld action defined in struts.xml file: <action name=&quot;HelloWorld&quot; class=&quot;net.roseindia.HelloWorld&quot;>      <result>/example/HelloWorld.jsp</result> </action>
View of Application The HelloWorld.jsp file is view in the Hello World example. Here is the code of HelloWorld.jsp file: <%@ page contentType=&quot;text/html; charset=UTF-8&quot; %> <%@ taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot; %> <html> <head>     <title><s:text name=&quot;HelloWorld.message&quot;/></title> </head> <body>    <h2><s:property value=&quot;message&quot;/></h2> <br> <a href=&quot;/struts2/&quot;>Back to Index page</a> </body> </html> <s:property value=&quot;message&quot;/>  is used to display the message from the action class and  <s:text name=&quot;HelloWorld.message&quot;/>   is used to display the message from the properties file.
Struts File Upload Example StrutsUploadForm.java): package  roseindia.net; import  org.apache.struts.action.*; import  org.apache.struts.upload.FormFile; public class  StrutsUploadForm  extends  ActionForm {    private  FormFile theFile;    public  FormFile getTheFile() {      return  theFile;   }    public void  setTheFile(FormFile theFile) {      this .theFile = theFile;   } }
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.upload.FormFile; public class StrutsUploadAction extends Action {    public ActionForward execute(     ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response) throws Exception{     StrutsUploadForm myForm = (StrutsUploadForm)form;         FormFile myFile = myForm.getTheFile();         String contentType = myFile.getContentType();         String fileName    = myFile.getFileName();         int fileSize       = myFile.getFileSize();         byte[] fileData    = myFile.getFileData();     System.out.println(&quot;contentType: &quot; + contentType);     System.out.println(&quot;File Name: &quot; + fileName);     System.out.println(&quot;File Size: &quot; + fileSize);         return mapping.findForward(&quot;success&quot;);  }  }  Creating Action Class StrutsUploadAction.java
Defining form Bean in struts-config.xml file Add the following entry in the struts-config.xml file for defining the form bean: <form-bean     name=&quot;FileUpload&quot;     type=“mysiute.net.StrutsUploadForm&quot;/> Defining Action Mapping Add the following action mapping entry in the struts-config.xml file: <action      path=&quot;/FileUpload&quot;      type=“mysite.net.StrutsUploadAction&quot;      name=&quot;FileUpload&quot;      scope=&quot;request&quot;      validate=&quot;true&quot;      input=&quot;/pages/FileUpload.jsp&quot;>      <forward name=&quot;success&quot; path=&quot;/pages/uploadsuccess.jsp&quot;/> </action>
Developing jsp page -  FileUpload.jsp <%@ taglib uri=&quot;/tags/struts-bean&quot; prefix=&quot;bean&quot; %> <%@ taglib uri=&quot;/tags/struts-html&quot; prefix=&quot;html&quot; %> <html:html locale=&quot;true&quot;> <head> <title>Struts File Upload Example</title> <html:base/> </head> <body bgcolor=&quot;white&quot;> <html:form action=&quot;/FileUpload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;> <table><tr> <td align=&quot;center&quot; colspan=&quot;2&quot;> <font size=&quot;4&quot;>Please Enter the Following Details</font> <td align=&quot;left&quot; colspan=&quot;2&quot;> <font color=&quot;red&quot;><html:errors/></font> <td align=&quot;right&quot;> File Name </td> <td align=&quot;left&quot;> <html:file property=&quot;theFile&quot;/>  <tr> <td align=&quot;center&quot; colspan=&quot;2&quot;> <html:submit>Upload File</html:submit> </table> </html:form> </body> </html:html>
uploadsuccess.jsp file <html> <head> <title>Success</title> </head> <body> <p align=&quot;center&quot;><font size=&quot;5&quot; color=&quot;#000080&quot;>File Successfully Received</font></p> </body> </html> Add the following line in the index.jsp to call the form <li> <html:link page=&quot;/pages/FileUpload.jsp&quot;>Struts File Upload</html:link> <br> Example shows you how to Upload File with Struts. </li>
 
Understanding ActionClass …  in the struts application extends Struts  'org.apache.struts.action.Action&quot; Class  …  acts as wrapper around the business logic and provides an inteface to the application's Model layer. …  acts as glue between the View and Model layer  …  transfers the data from the view layer to the specific business process layer and finally returns the processed data from business layer to the view layer
Understanding ActionClass … testAction.java import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class TestAction extends Action {   public ActionForward execute(     ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response) throws Exception{       return mapping.findForward(&quot;testAction&quot;);   } } Action Class process the specified HTTP request, create the corresponding HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 

More Related Content

What's hot

Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
elliando dias
 
Sun JSF Presentation
Sun JSF PresentationSun JSF Presentation
Sun JSF Presentation
Gaurav Dighe
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
Adil Jafri
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
Chapter6 web apps-tomcat
Chapter6 web apps-tomcatChapter6 web apps-tomcat
Chapter6 web apps-tomcat
Venkat Gowda
 

What's hot (19)

JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
JSP Technology II
JSP Technology IIJSP Technology II
JSP Technology II
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
 
Spring Framework -I
Spring Framework -ISpring Framework -I
Spring Framework -I
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
 
Sun JSF Presentation
Sun JSF PresentationSun JSF Presentation
Sun JSF Presentation
 
Jspprogramming
JspprogrammingJspprogramming
Jspprogramming
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
 
Spring Framework - III
Spring Framework - IIISpring Framework - III
Spring Framework - III
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
9. java server faces
9. java server faces9. java server faces
9. java server faces
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
 
Chapter6 web apps-tomcat
Chapter6 web apps-tomcatChapter6 web apps-tomcat
Chapter6 web apps-tomcat
 

Similar to Ibm

D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
Sunil Patil
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
Sunil Patil
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
divzi1913
 
What is struts_en
What is struts_enWhat is struts_en
What is struts_en
techbed
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
Long Nguyen
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
yesprakash
 

Similar to Ibm (20)

Adobe Flex4
Adobe Flex4 Adobe Flex4
Adobe Flex4
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
 
Flex_rest_optimization
Flex_rest_optimizationFlex_rest_optimization
Flex_rest_optimization
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Spring and DWR
Spring and DWRSpring and DWR
Spring and DWR
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
 
MVC
MVCMVC
MVC
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questions
 
Struts 1
Struts 1Struts 1
Struts 1
 
What is struts_en
What is struts_enWhat is struts_en
What is struts_en
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
Introduction to Alfresco Surf Platform
Introduction to Alfresco Surf PlatformIntroduction to Alfresco Surf Platform
Introduction to Alfresco Surf Platform
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 

More from techbed

1456.base boot
1456.base boot1456.base boot
1456.base boot
techbed
 
1455.ata atapi standards - 1-7
1455.ata atapi standards - 1-71455.ata atapi standards - 1-7
1455.ata atapi standards - 1-7
techbed
 
1454.ata features
1454.ata features1454.ata features
1454.ata features
techbed
 
1432.encoding concepts
1432.encoding concepts1432.encoding concepts
1432.encoding concepts
techbed
 
Flash cs4 tutorials_2009
Flash cs4 tutorials_2009Flash cs4 tutorials_2009
Flash cs4 tutorials_2009
techbed
 
Photoshop tut
Photoshop tutPhotoshop tut
Photoshop tut
techbed
 
Part 6 debugging and testing java applications
Part 6 debugging and testing java applicationsPart 6 debugging and testing java applications
Part 6 debugging and testing java applications
techbed
 
Lab 7b) test a web application
Lab 7b) test a web applicationLab 7b) test a web application
Lab 7b) test a web application
techbed
 
Lab 7a) debug a web application
Lab 7a) debug a web applicationLab 7a) debug a web application
Lab 7a) debug a web application
techbed
 
Part 7 packaging and deployment
Part 7 packaging and deploymentPart 7 packaging and deployment
Part 7 packaging and deployment
techbed
 
Lab 6) package and deploy a j2 ee application
Lab 6) package and deploy a j2 ee applicationLab 6) package and deploy a j2 ee application
Lab 6) package and deploy a j2 ee application
techbed
 
Lab 5b) create a java server faces application
Lab 5b) create a java server faces applicationLab 5b) create a java server faces application
Lab 5b) create a java server faces application
techbed
 
Lab 5a) create a struts application
Lab 5a) create a struts applicationLab 5a) create a struts application
Lab 5a) create a struts application
techbed
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
techbed
 
Part 5 running java applications
Part 5 running java applicationsPart 5 running java applications
Part 5 running java applications
techbed
 
Part 4 working with databases
Part 4 working with databasesPart 4 working with databases
Part 4 working with databases
techbed
 
Part 3 web development
Part 3 web developmentPart 3 web development
Part 3 web development
techbed
 
Lab 4) working with databases
Lab 4) working with databasesLab 4) working with databases
Lab 4) working with databases
techbed
 
Lab 3) create a web application
Lab 3) create a web applicationLab 3) create a web application
Lab 3) create a web application
techbed
 
Part 2 java development
Part 2 java developmentPart 2 java development
Part 2 java development
techbed
 

More from techbed (20)

1456.base boot
1456.base boot1456.base boot
1456.base boot
 
1455.ata atapi standards - 1-7
1455.ata atapi standards - 1-71455.ata atapi standards - 1-7
1455.ata atapi standards - 1-7
 
1454.ata features
1454.ata features1454.ata features
1454.ata features
 
1432.encoding concepts
1432.encoding concepts1432.encoding concepts
1432.encoding concepts
 
Flash cs4 tutorials_2009
Flash cs4 tutorials_2009Flash cs4 tutorials_2009
Flash cs4 tutorials_2009
 
Photoshop tut
Photoshop tutPhotoshop tut
Photoshop tut
 
Part 6 debugging and testing java applications
Part 6 debugging and testing java applicationsPart 6 debugging and testing java applications
Part 6 debugging and testing java applications
 
Lab 7b) test a web application
Lab 7b) test a web applicationLab 7b) test a web application
Lab 7b) test a web application
 
Lab 7a) debug a web application
Lab 7a) debug a web applicationLab 7a) debug a web application
Lab 7a) debug a web application
 
Part 7 packaging and deployment
Part 7 packaging and deploymentPart 7 packaging and deployment
Part 7 packaging and deployment
 
Lab 6) package and deploy a j2 ee application
Lab 6) package and deploy a j2 ee applicationLab 6) package and deploy a j2 ee application
Lab 6) package and deploy a j2 ee application
 
Lab 5b) create a java server faces application
Lab 5b) create a java server faces applicationLab 5b) create a java server faces application
Lab 5b) create a java server faces application
 
Lab 5a) create a struts application
Lab 5a) create a struts applicationLab 5a) create a struts application
Lab 5a) create a struts application
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
 
Part 5 running java applications
Part 5 running java applicationsPart 5 running java applications
Part 5 running java applications
 
Part 4 working with databases
Part 4 working with databasesPart 4 working with databases
Part 4 working with databases
 
Part 3 web development
Part 3 web developmentPart 3 web development
Part 3 web development
 
Lab 4) working with databases
Lab 4) working with databasesLab 4) working with databases
Lab 4) working with databases
 
Lab 3) create a web application
Lab 3) create a web applicationLab 3) create a web application
Lab 3) create a web application
 
Part 2 java development
Part 2 java developmentPart 2 java development
Part 2 java development
 

Recently uploaded

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

Ibm

  • 1.  
  • 2.
  • 3.
  • 4.
  • 5. Top Open Source Web Frameworks in Java
  • 6. MVC (Model-View-Controller) Architecture MODEL … how the underlying data is structured (Enterprise Data + Business Rules) VIEW … presentation to the user/client (User Interface Element) CONTROLLER … receives input from user and take appropriate action … element that performs the processing … manage the request of the web browser
  • 7.
  • 8.
  • 9.
  • 10. Programmers develop web applications and implement their SQL Queries with the business logics directly in the HTML document. <html><head><title>Important title</title></head><body> <someScript> dbConnection = openDBConnection(someDB) resultSet = dbConnection.executeQuery('select bookName from books') loop over resultSet{ print (resultSet.field('bookName') + '<br>') } </someScript> </body></html> Convenient for small projects only For large scale projects… need of separation
  • 11. <html:form action=&quot;someAction&quot;> Please give your name and the book title <br> Name: <html:text property=&quot;name&quot;/> <br> Title: <html:text property=&quot;title&quot;/> <br> <html:submit/> </html:form> Struts support resources files. In this files you can define a key for a text. bookDialog.formIntro=Please give your name and the title of the book. bookDialog.inputName=Name: bookDialog.bookTitle=Title: This key can be used to diplay the text in the JSP file. <html:form action=&quot;someAction&quot;> <bean:message key=&quot;bookDialog.formIntro&quot;/> <br> <bean:message key=&quot;bookDialog.inputName&quot;/> <html:text property=&quot;name&quot;/> <br> <bean:message key=&quot;bookDialog.bookTitle&quot;/> <html:text property=&quot;title&quot;/> <br> <html:submit/> </html:form>
  • 12. <html:form action=&quot;someAction&quot;> Please give your name and the book title <br> Name: <html:text property=&quot;name&quot;/> <br> Title: <html:text property=&quot;title&quot;/> <br> <html:submit/> </html:form> Struts support resources files. In this files you can define a key for a text. bookDialog.formIntro=Please give your name and the title of the book. bookDialog.inputName=Name: bookDialog.bookTitle=Title: This key can be used to diplay the text in the JSP file. <html:form action=&quot;someAction&quot;> <bean:message key=&quot;bookDialog.formIntro&quot;/> <br> <bean:message key=&quot;bookDialog.inputName&quot;/> <html:text property=&quot;name&quot;/> <br> <bean:message key=&quot;bookDialog.bookTitle&quot;/> <html:text property=&quot;title&quot;/> <br> <html:submit/> </html:form>
  • 13. Setting Up Development Environment Installing JDK: Download JDK latest. Follow the instruction given in the installation manual and install JDK. Installing Tomcat: Download Tomcat from the apache site and install it. To  test your installation go to your installation directory/bin and issue startup command to run the server. Open browser and type http://localhost:8080/ to test the Server . It should display the welcome page.
  • 14. Installing Struts Application Download latest version of Struts from the official site of Struts http:// jakarta.apache.org /struts . Extract the file into your favorite directory and copy struts-blank.war , struts-documentation.war and struts-example.war from &quot; jakarta-struts-1.1ebapps &quot; directory into &quot; jakarta-tomcat-5.0.4ebapps &quot; directory. struts-blank.war is the blank struts application which is useful in creating struts application from scratch. Use this file to create new web application. struts-documentation.war contains API and important documents for the struts application development. struts-example.war is simple MailReader Demonstration Application.
  • 15. MyApplication          |     ----src     // Java Source Code folder ----WEB-INF //within folder               |     ---------web.xml //file    ---------struts-config.xml //file    ---------struts-bean.tld //file    ---------struts-html.tld //file    ---------struts-logic.tld //file    ---------struts-nested.tld //file    ---------struts-template.tld //file    ---------struts-tiles.tld //file    ---------classes //folder    ---------lib //within folder   
  • 16.
  • 17. Developing First Struts Application … Rename struts-blank.war  to struts-tutorial.war from jakarta-tomcat-5.0.4ebapps and copy it to the &quot;jakarta-tomcat-5.0.4ebapps&quot; directory. Tomcat automatically extracts the file and loads the application.
  • 18. Extracting the content Now you can use the winzip to extract the content of struts-2.1.8.1-all.zip file. After extracting the file you will get following files/Directories:
  • 19. Extracting the content The apps directory contains: a) struts2-blank-2.1.8.1.war - Blank Struts 2.1.8 application, can use used to start the blank application b) struts2-mailreader-2.1.8.1.war - Struts 2.1.8 mail reader application demo c) struts2-portlet-2.1.8.1.war - Struts 2.1.8 portlet application d) struts2-rest-showcase-2.1.8.1.war - Example to use the REST (Representational State Transfer) services e) struts2-showcase-2.1.8.1.war - Struts 2.1.8 showcase applications. Other directories are docs, lib and src.
  • 21. Then run the tomcat and type http://localhost:8080/struts2-blank-2.1.8.1 in the browser . It should display the &quot;Struts is up and running ...&quot; message on the browser.
  • 22. Struts Showcase Example Copy the struts2-showcase-2.1.8.1.war file into webapps directory of Tomcat and then start the Tomcat.
  • 23. Struts Showcase Example … Now open the browser and type http://localhost:8080/struts2-showcase-2.1.8.1/ . Your browser should display the showcase application's home page.
  • 24. Struts Showcase Example … The showcase application provides following examples: Ajax Ajax Chat Action Chaining Config Browser Conversion CRUD Execute & Wait File Download File Upload FreemarkerHangman JavaServer  Faces Tags Tiles Token Validation Interactive Demo Person Manager Struts 1 Integration
  • 25. Screenshot of the Chat application
  • 26. Developing a Test Application - Display Message Web configuration file web.xml … To configure the Struts filter <filter>       <filter-name>struts2</filter-name>  <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> … then configure the filter mapping for struts2 filter:   <filter-mapping>       <filter-name>struts2</filter-name>      <url-pattern>/*</url-pattern> </filter-mapping>
  • 27. FILTERS FOR SECURITY In the web.xml file, you can specify the filter name and class, and initialization parameters. Then, associate the filter with a URL pattern in a filter mapping. <filter>   <filter-name>adminAccessFilter</filter-name>   <filter-class>      com.jamesholmes.minihr.security.AuthorizationFilter    </filter-class>   <init-param>     <param-name>roles</param-name>     <param-value>administrator</param-value>   </init-param>   <init-param>     <param-name>onError</param-name>     <param-value>/index.jsp</param-value>   </init-param> </filter> <filter-mapping>   <filter-name>adminAccessFilter</filter-name>   <url-pattern>/admin/*</url-pattern> </filter-mapping> The filter provides a basic security  mechanism for a firewall to determining what traffic passes through the firewall based on IP address details. Example – To restrict IP Addresses
  • 28. public class  IPFilterExample  implements  Filter{    public  IPFilterExample() {}    public final static  String IP = &quot;193.168.10.146&quot;;    private  FilterConfig filterConfig;       public void  init(FilterConfig config)  throws  ServletException{      this .filterConfig = config;   }    public void  doFilter(ServletRequest request, ServletResponse response,     FilterChain filterchain)  throws  IOException, ServletException {     response.setContentType(&quot;text/html&quot;);     PrintWriter out = response.getWriter();     out.println(&quot;<html><head><title>IP Filter Example</title></head>&quot;);     String userip = request.getRemoteAddr();     HttpServletResponse httpResponse =  null ;      if  (response  instanceof  HttpServletResponse){       httpResponse = (HttpServletResponse) response;     }      if  (IP.equals(userip)) {       httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN,&quot;You are not         allowed to access the servlet!&quot;);           }  else  {       filterchain.doFilter(request, response);       out.println(&quot;<body><h3><font color='green'>Passed successfully from IP       Filter<font></h3></body></html>&quot;);     }   }    public void  destroy() {} } IP FILTER
  • 29. MOVING BACK TO OUR TEST APPLICATION - WEB.XML file <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <web-app id=&quot;WebApp_9&quot; version=&quot;2.4&quot; xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;> <display-name>My Application Struts 2.8.1 Tutorials</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
  • 30. WRITING THE ACTION CLASS - HelloWorld.java import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport {     public String execute() throws Exception {         setMessage(getText(MESSAGE));         return SUCCESS;     }     public static final String MESSAGE = &quot;HelloWorld.message&quot;;     private String message;     public String getMessage() {         return message;     }     public void setMessage(String message) {         this.message = message;     } }
  • 31. HelloWorld.java The class extends com.opensymphony.xwork2.ActionSupport class. It provides a method getText(), to retrieve the message for the current local from the message resource file. The Struts framework executes the following default method :      public  String execute()  throws  Exception {         setMessage(getText(MESSAGE));          return  SUCCESS;     } This method is just setting the message and the returning the SUCCESS value, which is the result of the action.
  • 32. HelloWorld.java in Struts In this example HelloWorld.jsp is rendered and displayed to the user. Configuration of the HelloWorld action defined in struts.xml file: <action name=&quot;HelloWorld&quot; class=&quot;net.roseindia.HelloWorld&quot;>      <result>/example/HelloWorld.jsp</result> </action>
  • 33. View of Application The HelloWorld.jsp file is view in the Hello World example. Here is the code of HelloWorld.jsp file: <%@ page contentType=&quot;text/html; charset=UTF-8&quot; %> <%@ taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot; %> <html> <head>     <title><s:text name=&quot;HelloWorld.message&quot;/></title> </head> <body>    <h2><s:property value=&quot;message&quot;/></h2> <br> <a href=&quot;/struts2/&quot;>Back to Index page</a> </body> </html> <s:property value=&quot;message&quot;/> is used to display the message from the action class and <s:text name=&quot;HelloWorld.message&quot;/>  is used to display the message from the properties file.
  • 34. Struts File Upload Example StrutsUploadForm.java): package  roseindia.net; import  org.apache.struts.action.*; import  org.apache.struts.upload.FormFile; public class  StrutsUploadForm  extends  ActionForm {    private  FormFile theFile;    public  FormFile getTheFile() {      return  theFile;   }    public void  setTheFile(FormFile theFile) {      this .theFile = theFile;   } }
  • 35. import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.upload.FormFile; public class StrutsUploadAction extends Action {   public ActionForward execute(     ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response) throws Exception{     StrutsUploadForm myForm = (StrutsUploadForm)form;         FormFile myFile = myForm.getTheFile();         String contentType = myFile.getContentType();         String fileName    = myFile.getFileName();         int fileSize       = myFile.getFileSize();         byte[] fileData    = myFile.getFileData();     System.out.println(&quot;contentType: &quot; + contentType);     System.out.println(&quot;File Name: &quot; + fileName);     System.out.println(&quot;File Size: &quot; + fileSize);         return mapping.findForward(&quot;success&quot;);  } } Creating Action Class StrutsUploadAction.java
  • 36. Defining form Bean in struts-config.xml file Add the following entry in the struts-config.xml file for defining the form bean: <form-bean     name=&quot;FileUpload&quot;     type=“mysiute.net.StrutsUploadForm&quot;/> Defining Action Mapping Add the following action mapping entry in the struts-config.xml file: <action      path=&quot;/FileUpload&quot;      type=“mysite.net.StrutsUploadAction&quot;      name=&quot;FileUpload&quot;      scope=&quot;request&quot;      validate=&quot;true&quot;      input=&quot;/pages/FileUpload.jsp&quot;>      <forward name=&quot;success&quot; path=&quot;/pages/uploadsuccess.jsp&quot;/> </action>
  • 37. Developing jsp page - FileUpload.jsp <%@ taglib uri=&quot;/tags/struts-bean&quot; prefix=&quot;bean&quot; %> <%@ taglib uri=&quot;/tags/struts-html&quot; prefix=&quot;html&quot; %> <html:html locale=&quot;true&quot;> <head> <title>Struts File Upload Example</title> <html:base/> </head> <body bgcolor=&quot;white&quot;> <html:form action=&quot;/FileUpload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;> <table><tr> <td align=&quot;center&quot; colspan=&quot;2&quot;> <font size=&quot;4&quot;>Please Enter the Following Details</font> <td align=&quot;left&quot; colspan=&quot;2&quot;> <font color=&quot;red&quot;><html:errors/></font> <td align=&quot;right&quot;> File Name </td> <td align=&quot;left&quot;> <html:file property=&quot;theFile&quot;/>  <tr> <td align=&quot;center&quot; colspan=&quot;2&quot;> <html:submit>Upload File</html:submit> </table> </html:form> </body> </html:html>
  • 38. uploadsuccess.jsp file <html> <head> <title>Success</title> </head> <body> <p align=&quot;center&quot;><font size=&quot;5&quot; color=&quot;#000080&quot;>File Successfully Received</font></p> </body> </html> Add the following line in the index.jsp to call the form <li> <html:link page=&quot;/pages/FileUpload.jsp&quot;>Struts File Upload</html:link> <br> Example shows you how to Upload File with Struts. </li>
  • 39.  
  • 40. Understanding ActionClass … in the struts application extends Struts 'org.apache.struts.action.Action&quot; Class … acts as wrapper around the business logic and provides an inteface to the application's Model layer. … acts as glue between the View and Model layer … transfers the data from the view layer to the specific business process layer and finally returns the processed data from business layer to the view layer
  • 41. Understanding ActionClass … testAction.java import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class TestAction extends Action {   public ActionForward execute(     ActionMapping mapping,     ActionForm form,     HttpServletRequest request,     HttpServletResponse response) throws Exception{       return mapping.findForward(&quot;testAction&quot;);   } } Action Class process the specified HTTP request, create the corresponding HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic.
  • 42.
  • 43.