User Manual

Creating Data Access Object Implementation for JDBC
1. Create a com.hp.empinfo.service package and an EmployeeDao class under the
com.hp.empinfo.service package, as described in “Creating the Controller for EmpInfo
(page 54). This will contain the logic for handling Employee Database Transactions.
2. Modify the EmployeeDao.java class file to add the function for inserting employee details.
After modification, the EmployeeDao.java file must appear as:
package com.hp.empinfo.service;
import java.sql.SQLException;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
public class EmployeeDao extends JdbcDaoSupport{
public void insertDetail(int empid, String firstname,
String lastname, int age, String email)
throws SQLException
{
getJdbcTemplate().update("insert into employee values(?,?,?,?,?)",
new Object[] { empid,firstname,lastname,age,email});
}
}
Creating and Modifying Supporting Views to Display Business Data
To create and modify supporting views to display business data, create the JSP files to create the
view by completing the following steps:
1. Create the insertresult.jsp file in the Empinfo/WebContent/Web-INF/jsp directory
as described in “Creating the index.jsp File” (page 43).
2. Modify the insertresult.jsp file to provide a link to the insert.jsp page.
After modification, the insertresult.jsp file must appear as:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring Getting Started with EmpInfo Application</title>
</head>
<body>
<h2 align="center"> Insert Operation Successfully Executed </h2>
<br>
${model.add}
<br>
<br>
<br>
<h4><a href=<c:url value="insert.htm"/>>Insert Employee</a></h4>
</body>
</html>
3. Modify the insert.jsp file in the EmpInfo/WebContent/Web-INF/jsp/insert.jsp
directory to receive all the input data required to add a new employee record to the database,
by completing the following steps:
1. Delete the following <c:out> tag from the <body> tag.
<h3 align="center"><c:out value="${now}"/></h3>
2. Add the following lines of code in the body tag to receive all the inputs required to add
a new employee record.
Getting Started with Spring 63