Home Struts Struts Struts2.2.1 Databaseapps Writing jsp files in struts2.2.1

Ask Questions?

View Latest Questions


 
 

Writing jsp files in struts2.2.1
Posted on: February 5, 2011 at 12:00 AM
Advertisement
In this section, you will see how to create jsp files in struts application.

Writing JSP files in Struts2.2.1

It is a struts2.2.1 database connectivity application. Name of this application is 
Student_Admission_Application. In this application, you will see how to insert, 
search, update and delete record from database. Here, we are using MYSQL  
for database.

AdmissionForm.jsp

<%@taglib uri="/struts-tags" prefix="s"%>
<%@ 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">
<html>
<head>
<title>Student Admission Form</title>
</head>
<body>
<jsp:include page="header.jsp"></jsp:include>
<h3 style="color: green;">Student Admission Form</h3>
<s:form action="AdmissionAction" method="post">
<table border="1">
<tr>
<td><s:textfield name="name" label="Name"/></td>
</tr>
<tr>
<td><s:textfield name="fname" label="Father Name"></s:textfield></td>
</tr>
<tr>
<td><s:textfield name="dob" label="D_O_B(yyyy-mm-dd)"></s:textfield></td>
</tr>
<tr>
<td><s:textfield name="currentDate"
label="Current Date(yyyy-mm-dd)"></s:textfield></td>
</tr>
<tr>
<td><s:select list="clsseslist" label="class" name="class1"
headerKey="none" headerValue="None"></s:select></td>
</tr>
<tr>
<td><s:textfield name="address" label="Address"></s:textfield></td>
</tr>
<tr>
<td><s:textfield name="phoneno" label="PhoneNo"></s:textfield></td>
</tr>
<tr>
<td><s:textfield name="fee" label="Fee"></s:textfield></td>
</tr>
<tr>
<td><s:submit value="Process Admission" /><s:reset /></td>
</tr>
</table>
</s:form>
</body>
</html>

View Of Addmission Form

 

searchStudentresult.jsp

<%@taglib uri="/struts-tags" prefix="s"%>
<%@taglib uri="/struts-dojo-tags" prefix="sx"%>
<html>
<head>
<title>Student Information</title>
</head>
<body>
<h3>Strudent_Admission_Application</h3>
<h2>Search Student Record</h2>
<jsp:include page="header.jsp"></jsp:include>
<s:actionerror />
<form action="searchAction" method="post">
<table>
<tbody>
<tr>
<th colspan="2" style="color: green">Student Search Form</th>
</tr>
<tr>
<td><s:textfield name="s_name" label="Student Name">
</s:textfield></td>
</tr>
<tr align="center">
<td style="color: green">OR</td>
</tr>
<tr>
<td><s:textfield name="calss1" label="Sudent Class">
</s:textfield></td>
</tr>
<tr align="center">
<td style="color: green">OR</td>
</tr>
<tr>
<td><s:textfield name="s_roll" label="Student Roll Nubmer">
</s:textfield></td>
</tr>
<tr>
<td><s:submit value="Search" /><s:reset></s:reset></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

View Of Search Form

 

displayResult.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@page import="net.roseindia.model.StudentAdmissionModel" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Search Result</title>
</head>
<body>
<jsp:include page="header.jsp"></jsp:include>
<h2 style="color: green;">Search Result(Student Information)</h2>
<table border="1">
<tr>
<th>RollNo</th>
<th>Name</th>
<th>Father Name</th>
<th>D_O_B</th>
<th>Current_Date</th>
<th>Class</th>
<th>Address</th>
<th>PhoneNo</th>
<th>Edit</th>
</tr>
<!-- <s:bean name="net.roseindia.model.StudentAdmissionModel" id="student">-->
<!-- <s:param name="name" value="name"/>-->
<!-- <s:property value="#student.name" />-->
<!-- </s:bean>-->

<% 
StudentAdmissionModel model=(StudentAdmissionModel)request.getAttribute("data");

String dob=model.getDob();
String class1=model.getClass1();
String currentDate=model.getCurrentDate();
String address=model.getAddress();
String phoneno=model.getPhoneno();
long fee=model.getFee();

%>
<tr>
<td width="119"><%=model.getRoll()%></td>
<td width="119"><%=model.getName()%></td>
<td width="119"><%=model.getFname()%></td>
<td width="119"><%=model.getDob()%></td>
<td width="119"><%=model.getCurrentDate()%></td>
<td width="119"><%=model.getClass1()%></td>
<td width="119"><%=model.getAddress()%></td>
<td width="119"><%=model.getPhoneno()%></td>
<td width="119"><a href="./delete.action?id=<%=model.getRoll() %>">Delete</a>
<a href="./updateForm.action?id=<%=model.getRoll()%>">Update</a>
</td> 

</tr> 

</table>

</body>
</html>

View Of Display Result

 

SampleInterfaceImp.java

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="net.roseindia.dao.ApplicationDAO"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Update Page</title>
</head>
<jsp:include page="header.jsp"></jsp:include>
<%
String sRoll=request.getParameter("id");
int roll=Integer.parseInt(sRoll);
ApplicationDAO student=new ApplicationDAO();
StudentAdmissionModel studetModel=student.search(roll);

UpdateModel updateModel=new UpdateModel();
updateModel.setRoll(studetModel.getRoll());
updateModel.setName(studetModel.getName());
updateModel.setFname(studetModel.getFname());
updateModel.setFee(studetModel.getFee());
updateModel.setClass1(studetModel.getClass1());
updateModel.setAddress(studetModel.getAddress());

//UpdateModel model=student.search(roll);
System.out.println(updateModel.getName()); 
//String name=model.getName();
%>

<body>
<h2 style="color: green;">Record for update</h2>
<s:form action="updateAction">
<table border="1">
<tr>
<td><s:property value="name"/></td>
<td><s:textfield value="" label="Name"/></td>
</tr>
<tr>
<td><s:textfield value="%{re}" name="fname"
label="Father Name"></s:textfield></td>
</tr>
<tr>
<td><s:textfield value="%{session['D_O_B']}" name="dob"
label="Date_Of_Birth"></s:textfield></td>
</tr>
<tr>
<td><s:textfield value="%{session['Cur_Date']}"
name="currentDate" label="Current_Date"></s:textfield></td>
</tr>
<tr>
<td><s:textfield value="%{session['Class1']}" name="class1"
label="Class"></s:textfield></td>
</tr>
<tr>
<td><s:textfield value="%{session['Address']}" name="address"
label="Address"></s:textfield></td>
</tr>
<tr>
<td><s:textfield value="%{session['PhoneNo']}" name="phoneno"
label="Phone Number"></s:textfield></td>
</tr>
<s:submit name="Submit" value="Update"></s:submit>
</table>
</s:form>
</body>

<%@page import="net.roseindia.model.UpdateModel"%>
<%@page import="net.roseindia.model.StudentAdmissionModel"%></html>

View Of Update Form

 

Related Tags for Writing jsp files in struts2.2.1:


DMCA.com