0% found this document useful (0 votes)
28 views5 pages

Practical 8 Output

This document contains code for a Struts 2 web application that calculates the sum of two numbers. It includes JSP files for the input and results views, a Java action class to perform the calculation, and configuration files for Struts and web deployment. The input JSP allows entering two numbers and submitting to the SumAction, which calculates the sum and stores it in the model. The result JSP then displays the summed value.

Uploaded by

bakwas id
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

Practical 8 Output

This document contains code for a Struts 2 web application that calculates the sum of two numbers. It includes JSP files for the input and results views, a Java action class to perform the calculation, and configuration files for Struts and web deployment. The input JSP allows entering two numbers and submitting to the SumAction, which calculates the sum and stores it in the model. The result JSP then displays the summed value.

Uploaded by

bakwas id
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name:

Roll No:

PROGRAM CODE:

1)Input.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>


<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Struts2 beginner example application</title>
</head>
<body>
<center>
<h2>Calculate sum of two numbers</h2>
<s:form action="calculateSumAction" method="post">
<s:textfield name="x" size="10" label="Enter X" />
<s:textfield name="y" size="10" label="Enter Y" />
<s:submit value="Calculate" />
</s:form>
</center>
</body>
</html>

2) Result.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>


<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sum Result</title>
</head>
<body>
Sum of <s:property value="x"/>
and <s:property value="y"/>
is:
<s:property value="sum"/>
</body>
</html>

3)SumAction.java

package net.codejava.struts;

import com.opensymphony.xwork2.ActionSupport;

public class SumAction extends ActionSupport {


private int x;
private int y;
private int sum;

/**
* The action method
* @return name of view
*/
public String calculate() {
sum = x + y;
return SUCCESS;
}

// setters and getters for x, y, and sum:

public int getX() {


return x;
}

public void setX(int x) {


this.x = x;
}

public int getY() {


return y;
}

public void setY(int y) {


this.y = y;
}
public int getSum() {
return sum;
}

public void setSum(int sum) {


this.sum = sum;
}
}

4) struts.xml

<?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>
<package name="Struts2Beginner" extends="struts-default">
<action name="calculateSumAction" class="net.codejava.struts.SumAction"
method="calculate">
<result name="success">/Result.jsp</result>
<result name="input">/Input.jsp</result>
</action>
</package>
</struts>

5)web.xml

<?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"
id="WebApp_ID" version="3.0">
<display-name>Struts2Beginner</display-name>

<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>
</web-app>

OUTPUT:

You might also like