SlideShare a Scribd company logo
STRUTS 2 DATABASE ACCESS 
http://www.tuto rialspo int.co m/struts_2/struts_database _acce ss.htm Co pyrig ht © tuto rials po int.c om 
T his chapter will teah you how to access a database using Struts 2 in simple steps. Struts is a MVC framework 
and not a database framework but it provides excellent support for JPA/Hibernate integ ration. We shall look at 
the hibernate integ ration in a later chapter, but in this chapter we shall use plain old JDBC to access the database. 
T he first step in this chapter is to setup and prime our database. I am using MySQL as my database for this 
example. I have MySQL installed on my machine and I have created a new database called "struts_tutorial". I 
have created a table called log in and populated it with some values. Below is the script I used to create and 
populate the table. 
My MYSQL database has the default username "root" and "root123" password 
CREATE TABLE `struts_tutorial`.`login` ( 
`user` VARCHAR( 10 ) NOT NULL , 
`password` VARCHAR( 10 ) NOT NULL , 
`name` VARCHAR( 20 ) NOT NULL , 
PRIMARY KEY ( `user` ) 
) ENGINE = InnoDB; 
INSERT INTO `struts_tutorial`.`login` (`user`, `password`, `name`) 
VALUES ('scott', 'navy', 'Scott Burgemott'); 
Next step is to download the MySQL Connector jar file and placing this file in the WEB-INFlib folder of your 
project. After we have done this, we are now ready to create the action class. 
Create Action: 
T he action class has the properties corresponding to the columns in the database table. We have user, 
password and name as String attribues. In the action method, we use the user and password parameters to 
check if the user exists, if so , we display the user name in the next screen. If the user has entered wrong 
information, we send them to the log in screen ag ain. Following is the content of Log inAc tion.java file: 
package com.tutorialspoint.struts2; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import com.opensymphony.xwork2.ActionSupport; 
public class LoginAction extends ActionSupport { 
private String user; 
private String password; 
private String name; 
public String execute() { 
String ret = ERROR; 
Connection conn = null; 
try { 
String URL = "jdbc:mysql://localhost/struts_tutorial"; 
Class.forName("com.mysql.jdbc.Driver"); 
conn = DriverManager.getConnection(URL, "root", "root123"); 
String sql = "SELECT name FROM login WHERE"; 
sql+=" user = ? AND password = ?"; 
PreparedStatement ps = conn.prepareStatement(sql); 
ps.setString(1, user); 
ps.setString(2, password); 
ResultSet rs = ps.executeQuery(); 
while (rs.next()) { 
name = rs.getString(1);
ret = SUCCESS; 
} 
} catch (Exception e) { 
ret = ERROR; 
} finally { 
if (conn != null) { 
try { 
conn.close(); 
} catch (Exception e) { 
} 
} 
} 
return ret; 
} 
public String getUser() { 
return user; 
} 
public void setUser(String user) { 
this.user = user; 
} 
public String getPassword() { 
return password; 
} 
public void setPassword(String password) { 
this.password = password; 
} 
public String getName() { 
return name; 
} 
public void setName(String name) { 
this.name = name; 
} 
} 
Create main pag e: 
Now, let us create a JSP file index.jsp to collect the username and password. T his username and password will 
be checked ag ainst the database. 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix="s" uri="/struts-tags"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<title>Login</title> 
</head> 
<body> 
<form action="loginaction" method="post"> 
User:<br/><input type="text" name="user"/><br/> 
Password:<br/><input type="password" name="password"/><br/> 
<input type="submit" value="Login"/> 
</form> 
</body> 
</html> 
Create Views: 
Now let us create suc c ess.jsp file which will be invoked in case action returns SUCCESS, but we will have 
another view file in case of an ERROR is returned from the action. 
<%@ page contentType="text/html; charset=UTF-8" %> 
<%@ taglib prefix="s" uri="/struts-tags" %>
<html> 
<head> 
<title>Successful Login</title> 
</head> 
<body> 
Hello World, <s:property value="name"/> 
</body> 
</html> 
Following will be the view file error.jsp in case of an ERROR is returned from the action. 
<%@ page contentType="text/html; charset=UTF-8" %> 
<%@ taglib prefix="s" uri="/struts-tags" %> 
<html> 
<head> 
<title>Invalid User Name or Password</title> 
</head> 
<body> 
Wrong user name or password provided. 
</body> 
</html> 
Config uration Files: 
Finally, let us put everything tog ether using the struts.xml config uration file as follows: 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
"http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<constant name="struts.devMode" value="true" /> 
<package name="helloworld" extends="struts-default"> 
<action name="loginaction" 
method="execute"> 
<result name="success">/success.jsp</result> 
<result name="error">/error.jsp</result> 
</action> 
</package> 
</struts> 
Following is the content of web.xml file: 
<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
> 
<display-name>Struts 2</display-name> 
<welcome-file-list> 
<welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 
<filter> 
<filter-name>struts2</filter-name> 
<filter-class> 
org.apache.struts2.dispatcher.FilterDispatcher 
</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern> 
</filter-mapping> 
</web-app> 
Now, rig ht click on the project name and click Export > WAR File to create a War file. T hen deploy this WAR 
in the T omcat's webapps directory. Finally, start T omcat server and try to access URL 
http://localhost:8080/HelloWorldStruts2/index.jsp. T his will g ive you following screen: 
Enter a wrong user name and password. You should see the net pag e 
Now enter sc ott as user name and navy as password. You should see the net pag e

More Related Content

What's hot (20)

PPTX
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
PDF
Tomcat连接池配置方法V2.1
Zianed Hou
 
ODP
Msql
ksujitha
 
ZIP
Rails and alternative ORMs
Jonathan Dahl
 
PDF
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
DicodingEvent
 
DOCX
Java database connecticity steps
SKMohamedKasim
 
PPT
Synapse india reviews on php and sql
saritasingh19866
 
PDF
Python my SQL - create table
Learnbay Datascience
 
PDF
Python my sql database connection
Learnbay Datascience
 
DOC
( 15 ) Office 2007 Create A Membership Database
LiquidHub
 
PPT
Learning Java 4 – Swing, SQL, and Security API
caswenson
 
PPTX
MySQL
Hideo Amezawa
 
PPT
MySQL
Gouthaman V
 
PDF
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
DicodingEvent
 
PDF
Mysql connection
beben benzy
 
TXT
Excelsheet
amarnathprasad
 
PPTX
Html web sql database
AbhishekMondal42
 
DOCX
Spring 3.0
Ved Prakash Gupta
 
ODT
Mysql
ksujitha
 
PDF
Upgrade your javascript to drupal 8
Théodore Biadala
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
Tomcat连接池配置方法V2.1
Zianed Hou
 
Msql
ksujitha
 
Rails and alternative ORMs
Jonathan Dahl
 
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
DicodingEvent
 
Java database connecticity steps
SKMohamedKasim
 
Synapse india reviews on php and sql
saritasingh19866
 
Python my SQL - create table
Learnbay Datascience
 
Python my sql database connection
Learnbay Datascience
 
( 15 ) Office 2007 Create A Membership Database
LiquidHub
 
Learning Java 4 – Swing, SQL, and Security API
caswenson
 
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
DicodingEvent
 
Mysql connection
beben benzy
 
Excelsheet
amarnathprasad
 
Html web sql database
AbhishekMondal42
 
Spring 3.0
Ved Prakash Gupta
 
Mysql
ksujitha
 
Upgrade your javascript to drupal 8
Théodore Biadala
 

Viewers also liked (16)

PPTX
SEO 2017 Predictions
Adam Orchard
 
PDF
Struts2 - 101
Munish Gupta
 
PPTX
Christoph C Cemper - LAC 2017 - Link building & off-page SEO for 2017 and bey...
iGB Affiliate
 
PDF
How to Master SEO in 2017
Digital Vidya
 
PDF
SEO 2017 - How to Dominate Search
Navneet Kaushal
 
PPTX
Technical SEO: 2017 Edition - SEO & Love Verona 2017
Bastian Grimm
 
PDF
eTail West 2017: SEO Audits
Eric Wu
 
PPTX
Keeping Up With SEO in 2017 & Beyond
Rand Fishkin
 
PDF
How to Build SEO into Content Strategy
Jonathon Colman
 
PDF
10 Best Practices of a Best Company to Work For
O.C. Tanner
 
PDF
24 Time Management Hacks to Develop for Increased Productivity
Iulian Olariu
 
PDF
Leader's Guide to Motivate People at Work
Weekdone.com
 
PDF
Digitized Student Development, Social Media, and Identity
Paul Brown
 
PDF
Designing Teams for Emerging Challenges
Aaron Irizarry
 
PDF
Visual Design with Data
Seth Familian
 
PDF
3 Things Every Sales Team Needs to Be Thinking About in 2017
Drift
 
SEO 2017 Predictions
Adam Orchard
 
Struts2 - 101
Munish Gupta
 
Christoph C Cemper - LAC 2017 - Link building & off-page SEO for 2017 and bey...
iGB Affiliate
 
How to Master SEO in 2017
Digital Vidya
 
SEO 2017 - How to Dominate Search
Navneet Kaushal
 
Technical SEO: 2017 Edition - SEO & Love Verona 2017
Bastian Grimm
 
eTail West 2017: SEO Audits
Eric Wu
 
Keeping Up With SEO in 2017 & Beyond
Rand Fishkin
 
How to Build SEO into Content Strategy
Jonathon Colman
 
10 Best Practices of a Best Company to Work For
O.C. Tanner
 
24 Time Management Hacks to Develop for Increased Productivity
Iulian Olariu
 
Leader's Guide to Motivate People at Work
Weekdone.com
 
Digitized Student Development, Social Media, and Identity
Paul Brown
 
Designing Teams for Emerging Challenges
Aaron Irizarry
 
Visual Design with Data
Seth Familian
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
Drift
 
Ad

Similar to Struts database access (20)

PPTX
Struts 2 – Database Access
Ducat India
 
PDF
Step By Step Guide For Buidling Simple Struts App
Syed Shahul
 
PPT
Strutsjspservlet
Sagar Nakul
 
PPT
Strutsjspservlet
Sagar Nakul
 
PPT
Struts,Jsp,Servlet
dasguptahirak
 
PPTX
struts unit best pdf for struts java.pptx
ozakamal8
 
PPTX
7. struts
AnusAhmad
 
PPS
Struts Java I I Lecture 8
patinijava
 
PDF
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Rati Manandhar
 
PPT
Struts course material
Vibrant Technologies & Computers
 
PDF
Unit 07: Design Patterns and Frameworks (3/3)
DSBW 2011/2002 - Carles Farré - Barcelona Tech
 
PPTX
Web Technologies - forms and actions
Aren Zomorodian
 
PPTX
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
PDF
Struts2 notes
Rajiv Gupta
 
PDF
Struts An Open-source Architecture for Web Applications
elliando dias
 
DOCX
Struts notes
Rajeev Uppala
 
PDF
Java Web Programming [7/9] : Struts2 Basics
IMC Institute
 
PDF
Jsf Framework
Marimuthu Udayakumar
 
Struts 2 – Database Access
Ducat India
 
Step By Step Guide For Buidling Simple Struts App
Syed Shahul
 
Strutsjspservlet
Sagar Nakul
 
Strutsjspservlet
Sagar Nakul
 
Struts,Jsp,Servlet
dasguptahirak
 
struts unit best pdf for struts java.pptx
ozakamal8
 
7. struts
AnusAhmad
 
Struts Java I I Lecture 8
patinijava
 
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Rati Manandhar
 
Struts course material
Vibrant Technologies & Computers
 
Unit 07: Design Patterns and Frameworks (3/3)
DSBW 2011/2002 - Carles Farré - Barcelona Tech
 
Web Technologies - forms and actions
Aren Zomorodian
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
Struts2 notes
Rajiv Gupta
 
Struts An Open-source Architecture for Web Applications
elliando dias
 
Struts notes
Rajeev Uppala
 
Java Web Programming [7/9] : Struts2 Basics
IMC Institute
 
Jsf Framework
Marimuthu Udayakumar
 
Ad

Recently uploaded (20)

PPTX
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PPTX
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPT
introductio to computers by arthur janry
RamananMuthukrishnan
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PPT
introduction to networking with basics coverage
RamananMuthukrishnan
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PDF
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
Orchestrating things in Angular application
Peter Abraham
 
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
introductio to computers by arthur janry
RamananMuthukrishnan
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
introduction to networking with basics coverage
RamananMuthukrishnan
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 

Struts database access

  • 1. STRUTS 2 DATABASE ACCESS http://www.tuto rialspo int.co m/struts_2/struts_database _acce ss.htm Co pyrig ht © tuto rials po int.c om T his chapter will teah you how to access a database using Struts 2 in simple steps. Struts is a MVC framework and not a database framework but it provides excellent support for JPA/Hibernate integ ration. We shall look at the hibernate integ ration in a later chapter, but in this chapter we shall use plain old JDBC to access the database. T he first step in this chapter is to setup and prime our database. I am using MySQL as my database for this example. I have MySQL installed on my machine and I have created a new database called "struts_tutorial". I have created a table called log in and populated it with some values. Below is the script I used to create and populate the table. My MYSQL database has the default username "root" and "root123" password CREATE TABLE `struts_tutorial`.`login` ( `user` VARCHAR( 10 ) NOT NULL , `password` VARCHAR( 10 ) NOT NULL , `name` VARCHAR( 20 ) NOT NULL , PRIMARY KEY ( `user` ) ) ENGINE = InnoDB; INSERT INTO `struts_tutorial`.`login` (`user`, `password`, `name`) VALUES ('scott', 'navy', 'Scott Burgemott'); Next step is to download the MySQL Connector jar file and placing this file in the WEB-INFlib folder of your project. After we have done this, we are now ready to create the action class. Create Action: T he action class has the properties corresponding to the columns in the database table. We have user, password and name as String attribues. In the action method, we use the user and password parameters to check if the user exists, if so , we display the user name in the next screen. If the user has entered wrong information, we send them to the log in screen ag ain. Following is the content of Log inAc tion.java file: package com.tutorialspoint.struts2; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport { private String user; private String password; private String name; public String execute() { String ret = ERROR; Connection conn = null; try { String URL = "jdbc:mysql://localhost/struts_tutorial"; Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(URL, "root", "root123"); String sql = "SELECT name FROM login WHERE"; sql+=" user = ? AND password = ?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, user); ps.setString(2, password); ResultSet rs = ps.executeQuery(); while (rs.next()) { name = rs.getString(1);
  • 2. ret = SUCCESS; } } catch (Exception e) { ret = ERROR; } finally { if (conn != null) { try { conn.close(); } catch (Exception e) { } } } return ret; } public String getUser() { return user; } public void setUser(String user) { this.user = user; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } } Create main pag e: Now, let us create a JSP file index.jsp to collect the username and password. T his username and password will be checked ag ainst the database. <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Login</title> </head> <body> <form action="loginaction" method="post"> User:<br/><input type="text" name="user"/><br/> Password:<br/><input type="password" name="password"/><br/> <input type="submit" value="Login"/> </form> </body> </html> Create Views: Now let us create suc c ess.jsp file which will be invoked in case action returns SUCCESS, but we will have another view file in case of an ERROR is returned from the action. <%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %>
  • 3. <html> <head> <title>Successful Login</title> </head> <body> Hello World, <s:property value="name"/> </body> </html> Following will be the view file error.jsp in case of an ERROR is returned from the action. <%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Invalid User Name or Password</title> </head> <body> Wrong user name or password provided. </body> </html> Config uration Files: Finally, let us put everything tog ether using the struts.xml config uration file as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="helloworld" extends="struts-default"> <action name="loginaction" method="execute"> <result name="success">/success.jsp</result> <result name="error">/error.jsp</result> </action> </package> </struts> Following is the content of web.xml file: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" > <display-name>Struts 2</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name>
  • 4. <url-pattern>/*</url-pattern> </filter-mapping> </web-app> Now, rig ht click on the project name and click Export > WAR File to create a War file. T hen deploy this WAR in the T omcat's webapps directory. Finally, start T omcat server and try to access URL http://localhost:8080/HelloWorldStruts2/index.jsp. T his will g ive you following screen: Enter a wrong user name and password. You should see the net pag e Now enter sc ott as user name and navy as password. You should see the net pag e