Project Explorer
Library files
addstudent.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Student Registration</title> </head> <body> <h1>Enter Student Details</h1> <s:form action="add-student" method="post"> <s:textfield name="name" label="Name" placeholder="Name of the student"/> <s:textfield name="rollNo" label="Roll No" placeholder="Roll no of the student"/> <s:textfield name="branch" label="Branch" placeholder="Branch of the student"/> <s:textfield name="semester" label="Semester " placeholder="Semester of the student"/> <s:submit value="Submit Detail"/> </s:form> </body> </html> |
struts.xml
1 2 3 4 5 6 7 8 9 10 11 | <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" extends="struts-default"> <action name="add-student" class="com.ebhor.StudentAction"> <result name="success">/pages/showstudent.jsp</result> </action> </package> </struts> |
StudentAction.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | package com.ebhor; import com.opensymphony.xwork2.ActionSupport; public class Student extends ActionSupport { private String name; private String rollNo; private String branch; private String semester; public String execute() { System.out.println("Name " + getName() + " rollNo " + getRollNo() + " branch " + getBranch() + " smester " + getSemester()); return SUCCESS; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getRollNo() { return rollNo; } public void setRollNo(String rollNo) { this.rollNo = rollNo; } public String getBranch() { return branch; } public void setBranch(String branch) { this.branch = branch; } public String getSemester() { return semester; } public void setSemester(String semester) { this.semester = semester; } } |
showstudent.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Student Details</title> </head> <body> <h1>Student Detail</h1> Name: <s:property value="name"/><br/> Roll No: <s:property value="rollNo"/><br/> Branch: <s:property value="branch"/><br/> Semester: <s:property value="semester"/><br/> </body> </html> |
web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>pages/addstudent.jsp</welcome-file> </welcome-file-list> </web-app> |
Output