index.jsp
<br/><br/>
<hr/>
<center>
<a href="listDisplay.action">See List</a>
</center>
<hr/>
xwork.xml
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.1.dtd">
<xwork>
<include file="webwork-default.xml"/>
<package name="default" extends="webwork-default">
<action name="listDisplay" class="StudentAction" method="listDisplay">
<result name="success" type="freemarker">/list.ftl</result>
</action>
<action name="edit" class="StudentAction" method="edit">
<result name="success" type="freemarker">/student.ftl</result>
</action>
<action name="update" class="StudentAction" method="update">
<result name="success" type="freemarker">/list.ftl</result>
</action>
</package>
</xwork>
list.ftl
<br/><br/>
<hr/>
<table border="1" align="center">
<tr>
<th colspan="5">Student Table</th>
</tr>
<tr>
<th align="center">Name</td>
<th align="center">Number</td>
<th align="center">Comment</td>
<th align="center">Course</td>
<th align="center">Place</td>
</tr>
<#list students as student>
<tr>
<td align="center">
<a href='<@ww.url value="edit.action">
<@ww.param name="selectedStudent" value="${student_index}"/></@ww.url>'>${student.studentName}</a>
</td>
<td align="center">${student.no}</td>
<td align="center">${student.studentCmt}</td>
<td align="center">${student.selcourse}</td>
<td align="center">${student.selplace}</td>
</tr>
</#list>
</table>
<hr/>
<br/><br/>
student.ftl
<br/><br/>
<hr/><center>
<u><b>Student Edit Form</b></u><br/><br/>
<@ww.form action="update.action" method="POST">
<@ww.textfield label="Student Name" disabled="true" name="student.studentName" value="${student.studentName}"/>
<@ww.textfield label="Student Number" disabled="true" name="student.no" value="${student.no}"/>
<@ww.textarea label="Student Comment" rows="4" cols="10" name="student.studentCmt" value="${student.studentCmt}"/>
Course:
<@ww.comboBox label="Course" size="6" list="student.course" name="student.selcourse " value="${student.selcourse}" />
Place:
<select size="1" name="student.selplace">
<#list student.place as x>
<option value="${x}" <#if (x == student.selplace)>selected="selected"</#if>>
<@ww.text name="${x}"/>
</option>
</#list>
</select>
<@ww.submit value="Update" />
</@ww.form>
<hr/>
<br/><br/>
Student.java
package com.student;
import java.util.ArrayList;
import java.util.List;
public class Student {
String studentName="";
int no;
String studentCmt="";
List course=new ArrayList();
List place=new ArrayList();
String selcourse="";
String selplace="";
public Student()
{
course.add("mca");
course.add("mba");
course.add("btech");
course.add("mtech");
place.add("nellore");
place.add("hyderabad");
place.add("chennai");
place.add("bombay");
}
public List getCourse() {
return course;
}
public void setCourse(List course) {
this.course = course;
}
public String getSelcourse() {
return selcourse;
}
public void setSelcourse(String selcourse) {
this.selcourse = selcourse;
}
public Student(String studentName, int no, String studentCmt,String selcourse,String selplace) {
this();
this.studentName = studentName;
this.no = no;
this.studentCmt = studentCmt;
this.selcourse=selcourse;
this.selplace=selplace;
}
public Student(String studentName, int no) {
this.studentName = studentName;
this.no = no;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getStudentCmt() {
return studentCmt;
}
public void setStudentCmt(String studentCmt) {
this.studentCmt = studentCmt;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getSelplace() {
return selplace;
}
public void setSelplace(String selplace) {
this.selplace = selplace;
}
public List getPlace() {
return place;
}
public void setPlace(List place) {
this.place = place;
}
}
StudentActon.java
package com.student;
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork.ActionSupport;
public class StudentAction extends ActionSupport {
private Student student;
public List students=new ArrayList();
private int selectedStudent;
public int getSelectedStudent() {
return selectedStudent;
}
public void setSelectedStudent(int selectedStudent) {
this.selectedStudent = selectedStudent;
}
public StudentAction()
{
students.add(new Student("santhi",1,"hello","mca","nellore"));
students.add(new Student("vennela",2,"hello","mca","nellore"));
students.add(new Student("prasanthi",3,"hello","mca","nellore"));
students.add(new Student("madhuri",4,"hello","mca","nellore"));
students.add(new Student("sasaanka",5,"hello","mca","nellore"));
}
public void setStudent(Student Student) {
this.student = Student;
}
public Student getStudent() {
return student;
}
public String listDisplay() {
return SUCCESS;
}
public String edit() {
student=(Student) students.get(selectedStudent);
return SUCCESS;
}
public String update() {
student=(Student) students.get(selectedStudent);
return SUCCESS;
}
public List getStudents() {
return students;
}
public void setStudents(List students) {
this.students = students;
}
}
actions.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="StudentAction" class="com.student.StudentAction" />
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Sample App</display-name>
<filter>
<filter-name>springFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/actions.xml</param-value>
</context-param>
<filter>
<filter-name>webwork</filter-name>
<filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>webwork</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>/WEB-INF/webwork.tld</taglib-location>
</taglib>
</web-app>
No comments:
Post a Comment