This tutorial includes how to create simple login with Struts2 with hibernate database connectivity. :) Also i need to say i used maven for manage dependencies and eclipse Juno EE verison for developments with Mysql database..
First you must update your eclipse instance to work with maven, hibernate and struts. So i like to recommend to install Jboss tools plugin in you eclipse instance, Then create maven project like below
Then click next and tick create simple project like below image. Then
Then insert GroupID, Artfactid as you wants.
Eg : GroupId : com.sajeewi.struts
ArtfactId : Simple Login App
Packaging : war
Ok now we can start configure application environment to run on web server. Specially when we use maven to build java ee applications it didn't generates the WEB-INF folder and web.xml file. But when we create a dynamic web project in eclipse it automatically generates both folder and the xml file. :) So we have to manually create the web.xml file :(
Then create web.xml file in the WEB-INF folder and it should be like this
This xml file is special because it introduce struts2 to java application it is done by <filter>.
Then we must add dependencies to this project. So we have to update the pom.xml file to download dependencies to this project. Maven automatically detects the pom.xml changes and it automatically download the dependencies to the project. :) So update pom.xml like below to download dependencies :)
Ok now we have to clean and build the application with maven then it reads pom file and download the dependencies with specified versions. First we have do maven clean to this project. it will clean the target file in the project.
Then We must install using maven it will generate the .war file and whole packgings in the target folder including WEB-INF/lib folder.
ok now we are ready to code in the application :) First create the views for the project.Then We must install using maven it will generate the .war file and whole packgings in the target folder including WEB-INF/lib folder.
!!! I have imported struts tag libraries to create jsp views. This must include in every jsp to intergrate struts with java web application.
So we have to do this one only
Ok insert above tag and we can then use struts tags with jsp. So then we can create our views as we wants :)
ok now we have views that we want to make this project. Ok now starts the coding part. first we have to connect with database using hibernate. lets begin it with creating database.
ok all ready then we can create hibernate configuration file like below.
After came this step please fill it with your database configurations. after completion press test connection to test it. if there is no error within connection it shows success message.ok now we have views that we want to make this project. Ok now starts the coding part. first we have to connect with database using hibernate. lets begin it with creating database.
ok all ready then we can create hibernate configuration file like below.
Then you have to introduce your database configurations to hibernate. It can be do like this. hibernate.cfg.xml must be in src root but with the maven it automatically generate folder structure like below
So all the java supported file including struts.xml, hibernate configurations must be in java root. So generate it in the src root .
If you haven't generate any hibernate configurations using eclipse , you have to create connection profile here.
So connection profile must be empty. So you have to create it by using new connection creation. **** Important Sometimes eclipse not automatically detects the mysql-java-connector.jar. So you have to introduce its location manually.
Ok after all you have completed connection profile view.
Click finish then it generates the hibernate configuration file in the java root.
Ok now you have to create VO ( Value Objects ) , DAO ( Data Access Objects ), HibenateUtil File, Struts Configuration File to the project.So my recommendation is to keep separated folder for each and every file types :) Like DAO files in Dao package VO files in Vo package :)
Ok now you are ready to run this project :) But please wait you have to do one thing left. You have to clean and install using maven. It will clean the target folder and create new build new .war file in the project and generate all the files in the target folder as src's folder structure. Ok now you have run it :)
Access it with this
http://localhost:8080/SimpleLoginApp/login.jsp

















Comments
Post a Comment