Nearby lessons

5 of 19

Hibernate - Integration with MySQL

📌 What You Will Learn
  • Understand Hibernate - Integration with MySQL
  • See working code examples
  • Learn from common mistakes and Q&A

Learn Hibernate - Integration with MySQL step by step — simple explanations, complete programs with their output, common beginner mistakes, and exam-style MCQs.

Struts Overview

Framework is a semi implemented application, it will be used to design applications in

simplified manner.

Framework is prefabricated software units that programmer can share, customize, reuse in

order to simplify application development.

Framework is the collection of predefined classes and interfaces to simplify application

development.

In general, in Applications development, Frameworks will provide the following advantages.

  • Frameworks will provide common implementation in all the projects as predefined

implementation

EX: Controller Servlets and the services like I18N, Exception Handling, Validations ,.....

  • Frameworks will provide standard template to design applications.
  • Frameworks will provide standard flow of execution between the components.
  • Frameworks will reduce application development time.
  • Frameworks will reduce application development cost.
  • Frameworks will improve productivity.
  • Frameworks will provide modularity in application development.

There are two types of Frameworks.

  • Web Frameworks
  • Application Frameworks

What is the difference between web frameworks and Application Frameworks?

Answer:

Web Frameworks will provide very good environment to prepare and execute web applications

only.

EX: Struts, JSF.

Application Frameworks will provide very good environment to prepare and execute any type of

JAVA/J2EE Applications including Standalone Applications, Web applications, Distributed

Applications,

EX: Spring

Struts is MVC based web framework provided by Apache Software Foundations.

Struts is existed in two versions.

Struts Overview

If we want to prepare Struts applications in Struts1.x version then we have to use the following

components

  • View
  • Deployment Descriptor
  • Controller [ActionServlet]
  • Action class
  • Action Form
  • Struts Configuration File
  • View:

In Struts applications, View part is representing presentation part.

In web applications, there are two types of presentation part.

  • Informational Presentation part
  • Form Based Presentation part
  • Informational Presentation part

This type view part is able to provide only information to the user, which includes status of the

server side actions like Success, failure, ... and display a particular database table data,.....

EXAMPLE: success.html

<h1> Login Success </h1>

  • Form Based Presentation part:

This type of view part is able to provide a form to collect data from users and to submit data to the

server side applications.

In Struts applications, to prepare Presentation part we are able to use plain HTML tags, but, which

are not suggestible. In Struts applications it is suggestible to use Struts provided tag library.

EX: loginform.html

Example02
JCode Cell
1 
2Struts1.x
3Struts2.x
4

Struts Overview

The above login form with Struts provided html tag library

EX: loginform.jsp

Example03
JCode Cell
1 
2<html>
3<body>
4<form method="POSt" action="login.*">
5<table>
6<tr>
7<td>User Name</td>
8<td><input type="text" name="uname"/></td>
9</tr>
10<tr>
11<td>Password</td>
12<td><input type="password" name="upwd"/></td>
13</tr>
14<tr>
15<td><ipnut type="submit" value="Login"/></td>
16</tr>
17</table></form></body></html>
18

Struts Overview

Deployment descriptor is web.xml file, it will provide description about our web application which is

required by the container in order to perform server side actions.

In general, in web applications, web.xml file will provide the following configuration details.

  • Display names configurations.
  • Welcome Files Configurations.
  • Servlets configurations
  • Filters Configurations
  • Listeners Configurations.
  • Session time out configurations
  • Error Pages Configurations
  • Taglib configurations

In Struts based web applications, the main intention of web.xml file is to configure controller

Servlet that is ActionServlet.

EX:

Example04
JCode Cell
1 
2<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
3<html:html>
4<body>
5<html:form method="POST" action="login.do">
6<table>
7<tr>
8<td>User Name</td>
9<td><html:text property="uname"/></td>
10</tr>
11<tr>
12<td>Password</td>
13<td><html:password property="upwd"/></td>
14</tr>
15<tr>
16<td><html:submit>Login</html:submit></td>
17</tr>
18</table></html:form></body></html>
19Deployment Descriptor:
20

Struts Overview

In Struts Framework, ActionServlet is predefined Controller, it was provided in the form of

org.apache.struts.action.ActionServlet .

In Struts applications, ActionServlet will perform the following actions.

  • ActionServlet will take request from Client.
  • ActionServlet will identify the names and locations of the ActionForm and Action class

through Struts configuration file.

  • ActionServlet will load , instantiate ActionForm class.
  • ActionServlet will store form data in ActionForm object.
  • ActionServlet will load and instantiation Action class.
  • ActionServlet will execute execute(--) method in Action class.
  • ActionServlet will identify view page through Struts configuration file.
  • ActionServlet will forward request to view page inorder to generate response.

Note: In Struts applications, ActionServlet is performing all the above actions by using

"RequestProcessor" internally.

  • Action Class or Controller Component:

In Struts based web applications, the main intention of ActionForm or FormBean component is to

manage a particular form data at Server side inorder to perform Server side data validations, to

transfer data from Controller layer to model layer or Vie layer,.....

To prepare Form Bean components in Struts applications we have to use the following rules and

regulations.

  • Declare an user defined class, it must be extended from

org.apache.struts.action.ActionForm .

  • Form Bean class must be public, it must not be abstract and final.
  • In Form Bean class, we must declare properties with the same names of the form

properties.

  • In Form Bean class we must declare all properties as private and all bahaviours as public.
  • In FormBean class , we must provide a seperate set of setXXX() and getXXX() methods

for each and every property.

  • In FormBean class, if we want to provide any constructor then we can provide constructor

but that constructor must be public and 0-arg constructor.

  • In FormBean class, we can override equals(-) method and hashCode() method as per

the requirement.

Example05
JCode Cell
1 
2<web-app>
3<servlet>
4<servlet-name>actionServlet</servlet-name>
5<servlet-class>org.apache.struts.action.ActionServlet
6</servlet-class>
7<load-on-startup>1</load-on-startup>
8</servlet>
9<servlet-mapping>
10<servlet-name>actionServlet</servlet-name>
11<url-pattern>*.do</url-pattern>
12</servlet-mapping>
13</web-app>
14Controller [ActionServlet]
15
📝 Key Takeaways
  • Key ideas of Hibernate - Integration with MySQL explained simply
  • Ready-to-use code examples
  • Exam-style questions at the end