0% found this document useful (0 votes)
12 views36 pages

WT Outputs

The document contains multiple HTML, XML, XSL, and SQL files related to a restaurant and student/employee login systems. The restaurant section includes a menu, services offered, and a booking form, while the login sections provide JSP, XML configuration, and servlet code for handling user authentication. Additionally, SQL scripts are provided for creating and populating the necessary database tables for both students and employees.

Uploaded by

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

WT Outputs

The document contains multiple HTML, XML, XSL, and SQL files related to a restaurant and student/employee login systems. The restaurant section includes a menu, services offered, and a booking form, while the login sections provide JSP, XML configuration, and servlet code for handling user authentication. Additionally, SQL scripts are provided for creating and populating the necessary database tables for both students and employees.

Uploaded by

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

index.

html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Delicious Bites - Restaurant</title>
<!-- External CSS -->
<link rel="stylesheet" href="style.css">

<!-- Internal CSS -->


<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
}

h1 {
color: darkred;
text-align: center;
}

table {
width: 80%;
margin: auto;
border-collapse: collapse;
}

th, td {
padding: 10px;
border: 1px solid #aaa;
}

ul {
list-style-type: square;
}

.form-section {
background-color: #fff3e0;
padding: 20px;
width: 50%;
margin: 20px auto;
}
</style>
</head>
<body>

<h1>Welcome to Delicious Bites</h1>

<!-- Inline CSS -->


<p style="text-align: center; font-size: 18px;">Enjoy the best food in town with a cozy
ambiance!</p>

<!-- Image with Link -->


<div style="text-align: center;">
<a href="menu.jpg"><img src="restaurant.jpg" alt="Restaurant Image" width="600"></a>
</div>

<!-- Menu Table -->


<h2 style="text-align:center;">Today's Specials</h2>
<table>
<tr>
<th>Dish</th>
<th>Price</th>
</tr>
<tr>
<td>Grilled Chicken</td>
<td>$12</td>
</tr>
<tr>
<td>Veggie Pasta</td>
<td>$10</td>
</tr>
<tr>
<td>Cheese Pizza</td>
<td>$9</td>
</tr>
</table>

<!-- List of Services -->


<h2>Our Services</h2>
<ul>
<li>Dine-In</li>
<li>Takeaway</li>
<li>Online Ordering</li>
<li>Party Bookings</li>
</ul>
<!-- Contact Form -->
<div class="form-section">
<h2>Book a Table</h2>
<form action="/submit_booking" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br><br>

<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>

<label for="date">Date:</label><br>
<input type="date" id="date" name="date" required><br><br>

<label for="people">No. of People:</label><br>


<input type="number" id="people" name="people" required><br><br>

<input type="submit" value="Book Now">


</form>
</div>

<h2>Find Us on the Map</h2>


<iframe
src="https://maps.google.com/maps?q=restaurant&t=&z=13&ie=UTF8&iwloc=&output=embed"
width="600" height="400" style="display: block; margin: auto;"
frameborder="0"></iframe>

</body>
</html>
style.css
body {
margin: 0;
padding: 0;
}

h2 {
color: #d84315;
text-align: center;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"] {
width: 100%;
padding: 8px;
margin-top: 4px;
border: 1px solid #ccc;
}

input[type="submit"] {
background-color: #d84315;
color: white;
padding: 10px 15px;
border: none;
cursor: pointer;
}
Website
Xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="employees.xsl"?>
<employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="employees.xsd">
<employee>
<id>101</id>
<name>John Doe</name>
<department>IT</department>
<designation>Software Engineer</designation>
<salary>60000</salary>
</employee>
<employee>
<id>102</id>
<name>Jane Smith</name>
<department>HR</department>
<designation>HR Manager</designation>
<salary>75000</salary>
</employee>
</employees>

Dtd
<!ELEMENT employees (employee+)>
<!ELEMENT employee (id, name, department, designation, salary)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT department (#PCDATA)>
<!ELEMENT designation (#PCDATA)>
<!ELEMENT salary (#PCDATA)>

Xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="employees">
<xs:complexType>
<xs:sequence>
<xs:element name="employee" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="department" type="xs:string"/>
<xs:element name="designation" type="xs:string"/>
<xs:element name="salary" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<head>
<title>Employee List</title>
<style>
table {
border-collapse: collapse;
width: 70%;
margin: 20px auto;
}
th, td {
border: 1px solid #333;
padding: 8px 12px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h2 style="text-align:center;">Employee Details</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Department</th>
<th>Designation</th>
<th>Salary</th>
</tr>
<xsl:for-each select="employees/employee">
<tr>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="department"/></td>
<td><xsl:value-of select="designation"/></td>
<td><xsl:value-of select="salary"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Output
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Student Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f2f2f2;
padding: 20px;
}

.container {
background: #fff;
padding: 30px;
border-radius: 10px;
max-width: 500px;
margin: auto;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
}

input[type="text"],
input[type="email"],
input[type="tel"] {
width: 100%;
padding: 10px;
margin: 8px 0;
border-radius: 5px;
border: 1px solid #ccc;
}

button {
width: 100%;
padding: 12px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}

button:hover {
background-color: #218838;
}

.error {
color: red;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h2>Student Registration Form</h2>
<form id="registrationForm" onsubmit="return validateForm()">
<label for="name">Full Name:</label>
<input type="text" id="name" name="name" />

<label for="email">Email:</label>
<input type="email" id="email" name="email" />

<label for="phone">Phone Number:</label>


<input type="tel" id="phone" name="phone" />

<label for="course">Course:</label>
<input type="text" id="course" name="course" />

<p class="error" id="errorMsg"></p>

<button type="submit">Register</button>
</form>
</div>

<script>
function validateForm() {
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const phone = document.getElementById("phone").value.trim();
const course = document.getElementById("course").value.trim();
const errorMsg = document.getElementById("errorMsg");

// Email pattern
const emailPattern = /^[^ ]+@[^ ]+\.[a-z]{2,3}$/;
// Phone pattern: 10 digits only
const phonePattern = /^[0-9]{10}$/;

if (!name || !email || !phone || !course) {


errorMsg.textContent = "All fields are mandatory.";
return false;
}

if (!emailPattern.test(email)) {
errorMsg.textContent = "Please enter a valid email address.";
return false;
}

if (!phonePattern.test(phone)) {
errorMsg.textContent = "Please enter a valid 10-digit phone number.";
return false;
}

errorMsg.textContent = "";
alert("Registration Successful!");
return true;
}
</script>
</body>
</html>
Output
1.​Student Login
Jsp
<%@ page language="java" %>
<html>
<head><title>Student Login</title></head>
<body>
<h2>Student Login</h2>
<form action="StudentLoginServlet" method="post">
Username: <input type="text" name="username" required /><br/>
Password: <input type="password" name="password" required /><br/>
<input type="submit" value="Login" />
</form>
</body>
</html>

xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
version="3.1">

<servlet>
<servlet-name>StudentLoginServlet</servlet-name>
<servlet-class>com.studentapp.servlet.StudentLoginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>StudentLoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

</web-app>

servlet
package com.studentapp.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class StudentLoginServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

String username = request.getParameter("username");


String password = request.getParameter("password");

try {
Class.forName("com.mysql.cj.jdbc.Driver"); // MySQL 8.0+
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/studentdb", "root", "password");

PreparedStatement pst = conn.prepareStatement(


"SELECT * FROM students WHERE username=? AND password=?");
pst.setString(1, username);
pst.setString(2, password);

ResultSet rs = pst.executeQuery();

if (rs.next()) {
out.println("<h2>Login Successful. Welcome, " + username + "!</h2>");
} else {
out.println("<h2>Invalid Username or Password</h2>");
}

conn.close();

} catch (Exception e) {
out.println("Database connection error: " + e.getMessage());
}

out.close();
}
}

SQL
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL
);
USE studentdb;
INSERT INTO students (username, password) VALUES ('Asher', 'pass123');
INSERT INTO students (username, password) VALUES ('Soham', 'pass123');
INSERT INTO students (username, password) VALUES ('Digvijay', 'pass123');

Output
2.​Employee Login

Jsp
<%@ page language="java" %>
<html>
<head><title>Employee Login</title></head>
<body>
<h2>Employee Login</h2>
<form action="empLogin" method="post">
Username: <input type="text" name="username" required /><br/>
Password: <input type="password" name="password" required /><br/>
<input type="submit" value="Login" />
</form>
</body>
</html>

Xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
version="3.1">

<servlet>
<servlet-name>EmployeeLoginServlet</servlet-name>
<servlet-class>com.employeeapp.servlet.EmployeeLoginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>EmployeeLoginServlet</servlet-name>
<url-pattern>/empLogin</url-pattern>
</servlet-mapping>

</web-app>

Servlet
package com.employeeapp.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class EmployeeLoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

String username = request.getParameter("username");


String password = request.getParameter("password");

try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/employeedb", "root", "password");

PreparedStatement pst = conn.prepareStatement(


"SELECT * FROM employees WHERE username=? AND password=?");
pst.setString(1, username);
pst.setString(2, password);

ResultSet rs = pst.executeQuery();

if (rs.next()) {
out.println("<h2>Login Successful. Welcome, " + username + "!</h2>");
} else {
out.println("<h2>Invalid Username or Password</h2>");
}

conn.close();

} catch (Exception e) {
out.println("Database connection error: " + e.getMessage());
}

out.close();
}
}
SQL
USE employeedb;

CREATE TABLE employees (


id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL
);

INSERT INTO employees (username, password) VALUES ('employee1', 'emp123');


INSERT INTO employees (username, password) VALUES ('employee2', 'emp123');
INSERT INTO employees (username, password) VALUES ('employee3', 'emp123');

Output


SQL
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
position VARCHAR(100)
);

Database connection
<?php
$conn = new mysqli("localhost", "root", "", "employee_db");

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

View + form to add new employee


<?php include "db.php"; ?>

<h2>Add Employee</h2>
<form action="insert.php" method="post">
Name: <input type="text" name="name" required><br>
Email: <input type="email" name="email" required><br>
Position: <input type="text" name="position" required><br>
<input type="submit" value="Add">
</form>

<h2>Employee List</h2>
<?php
$result = $conn->query("SELECT * FROM employees");
while($row = $result->fetch_assoc()) {
echo "{$row['name']} - {$row['email']} - {$row['position']}
<a href='edit.php?id={$row['id']}'>Edit</a> |
<a href='delete.php?id={$row['id']}'>Delete</a><br>";
}
?>
Insert
<?php
include "db.php";

$name = $_POST['name'];
$email = $_POST['email'];
$position = $_POST['position'];

$conn->query("INSERT INTO employees (name, email, position) VALUES ('$name', '$email',


'$position')");
header("Location: index.php");
?>

Delete
<?php
include "db.php";

$id = $_GET['id'];
$conn->query("DELETE FROM employees WHERE id=$id");
header("Location: index.php");
?>

Edit
<?php
include "db.php";
$id = $_GET['id'];
$result = $conn->query("SELECT * FROM employees WHERE id=$id");
$row = $result->fetch_assoc();
?>

<form action="update.php" method="post">


<input type="hidden" name="id" value="<?= $row['id'] ?>">
Name: <input type="text" name="name" value="<?= $row['name'] ?>"><br>
Email: <input type="email" name="email" value="<?= $row['email'] ?>"><br>
Position: <input type="text" name="position" value="<?= $row['position'] ?>"><br>
<input type="submit" value="Update">
</form>
Update
<?php
include "db.php";

$id = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$position = $_POST['position'];

$conn->query("UPDATE employees SET name='$name', email='$email', position='$position'


WHERE id=$id");
header("Location: index.php");
?>

Output

SQL
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
position VARCHAR(100)
);

Database Connection
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "employee_data";

$conn = new mysqli($host, $user, $pass, $db);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

Insert
<?php
include 'db.php';

if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['position'])) {


$name = $_POST['name'];
$email = $_POST['email'];
$position = $_POST['position'];

$stmt = $conn->prepare("INSERT INTO employees (name, email, position) VALUES (?, ?,


?)");
$stmt->bind_param("sss", $name, $email, $position);

if ($stmt->execute()) {
echo "Employee added successfully!";
} else {
echo "Error: " . $stmt->error;
}

$stmt->close();
$conn->close();
}
?>

Fetch
<?php
include 'db.php';

$sql = "SELECT * FROM employees ORDER BY id DESC";


$result = $conn->query($sql);

if ($result->num_rows > 0) {
echo "<table border='1' cellpadding='10'>
<tr><th>ID</th><th>Name</th><th>Email</th><th>Position</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['email'] . "</td>
<td>" . $row['position'] . "</td>
</tr>";
}
echo "</table>";
} else {
echo "No employees found.";
}
$conn->close();
?>

Index
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Employee Management</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

<h2>Add Employee</h2>
<form id="employeeForm">
Name: <input type="text" id="name"><br><br>
Email: <input type="email" id="email"><br><br>
Position: <input type="text" id="position"><br><br>
<button type="submit">Add</button>
</form>

<hr>

<h2>Employee List</h2>
<div id="employeeTable"></div>

<script>
$(document).ready(function() {
loadEmployees(); // load data on page load

$("#employeeForm").on("submit", function(e) {
e.preventDefault();
var name = $("#name").val();
var email = $("#email").val();
var position = $("#position").val();

$.ajax({
url: "insert.php",
type: "POST",
data: { name: name, email: email, position: position },
success: function(response) {
alert(response);
$("#employeeForm")[0].reset();
loadEmployees(); // refresh the table
}
});
});

function loadEmployees() {
$.ajax({
url: "fetch.php",
type: "GET",
success: function(data) {
$("#employeeTable").html(data);
}
});
}
});
</script>

</body>
</html>

Output
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_2_5.xsd"
​ id="WebApp_ID" version="2.5">
​ <display-name>LoginFormStruts1</display-name>

​ <servlet>
​ ​ <servlet-name>action</servlet-name>
​ ​ <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
​ ​ <init-param>
​ ​ ​ <param-name>config</param-name>
​ ​ ​ <param-value>
/WEB-INF/struts-config.xml
</param-value>
​ ​ </init-param>
​ ​ <load-on-startup>1</load-on-startup>
​ </servlet>

​ <servlet-mapping>
​ ​ <servlet-name>action</servlet-name>
​ ​ <url-pattern>*.do</url-pattern>
​ </servlet-mapping>

​ <welcome-file-list>
​ ​ <welcome-file>index.jsp</welcome-file>
​ </welcome-file-list>

</web-app>

Login Form
package com.example.javawebtutor.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LoginForm extends ActionForm {


​ private String userName = null;
​ private String password = null;

​ public String getUserName() {


​ ​ return userName;
​ }

​ public void setUserName(String userName) {


​ ​ this.userName = userName;
​ }

​ public String getPassword() {


​ ​ return password;
​ }

​ public void setPassword(String password) {


​ ​ this.password = password;
​ }

​ @Override
​ public void reset(ActionMapping mapping, HttpServletRequest request) {
​ ​ this.password = null;
​ }

Action Class
package com.example.javawebtutor.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.example.javawebtutor.form.LoginForm;

public class LoginAction extends Action {


​ @Override
​ public ActionForward execute(ActionMapping mapping, ActionForm form,
​ ​ ​ HttpServletRequest request, HttpServletResponse response)
​ ​ ​ throws Exception {
​ ​ LoginForm loginForm = (LoginForm) form;

​ ​ if (loginForm.getUserName() == null || loginForm.getPassword() == null


​ ​ ​ ​ || !loginForm.getUserName().equalsIgnoreCase("Asher")
​ ​ ​ ​ || !loginForm.getPassword().equals("Wycliffe")) {
​ ​ ​ return mapping.findForward("success");
​ ​ } else
​ ​ ​ return mapping.findForward("failure");
​ }

struts config
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
​ ​
<struts-config>
<form-beans>
<form-bean name="loginForm" type="com.example.javawebtutor.form.LoginForm"/>
</form-beans>
<action-mappings>
​ <action name="loginForm" path="/login"
type="com.example.javawebtutor.action.LoginAction" scope="request" input="/login.jsp">
​ <forward name="failure" path="/login.jsp" redirect="true"/>
​ <forward name="success" path="/success.jsp" redirect="true"/>
​ </action>
</action-mappings>
</struts-config>

login jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
​ <html:form action="/login" focus="userName">
​ Username : <html:text property="userName" />
​ ​ <br>
​ Password : <html:password property="password" />
​ ​ <br>
​ ​ <html:submit value="login" />
​ </html:form>

</body>
</html>

success jsp
<%@ 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>Successful Login Page</title>
</head>
<body>
​ <h2>Welcome</h2>
</body>
</html>

index jsp
<jsp:forward page="/login.jsp"></jsp:forward>
Output
index html
<!DOCTYPE html>
<html ng-app="taskApp">
<head>
<meta charset="UTF-8">
<title>AngularJS Task Manager</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script src="app.js"></script>
<style>
body { font-family: Arial; margin: 20px; }
.done { text-decoration: line-through; color: gray; }
.task { margin-bottom: 10px; }
input[type="text"] { padding: 5px; }
button { margin-left: 5px; }
</style>
</head>
<body ng-controller="TaskController">

<h1> 📝 Task Manager</h1>


<input type="text" ng-model="newTask" placeholder="Enter task..." />
<button ng-click="addTask()">Add</button>

<div ng-repeat="task in tasks" class="task">


<input type="checkbox" ng-model="task.completed" />


<span ng-class="{done: task.completed}">{{ task.name }}</span>
<button ng-click="removeTask($index)"> </button>
</div>

</body>
</html>

app js
var app = angular.module('taskApp', []);

app.controller('TaskController', function ($scope) {


$scope.tasks = [
{ name: 'Learn AngularJS', completed: false },
{ name: 'Build a web app', completed: false }
];

$scope.addTask = function () {
if ($scope.newTask) {
$scope.tasks.push({ name: $scope.newTask, completed: false });
$scope.newTask = '';
}
};

$scope.removeTask = function (index) {


$scope.tasks.splice(index, 1);
};
});

Output
form.html
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body bgcolor="blue">
<h1>Calculator</h1>
<hr>

<form action="webappadd.jsp" method="POST">


<p>
Enter first value:<br>
<input type="text" name="num1" size="25"><br>
</p>

<p>
Enter second value:<br>
<input type="text" name="num2" size="25"><br>
</p>

<b>Select your choice:</b><br>


<input type="radio" name="group1" value="add"> Addition<br><br>

<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</p>
</form>
</body>
</html>

webappadd.jsp
<%@ page contentType=”text/html; charset=UTF-8” %>
<%@ page import=”com.add.*, javax.naming.*, javax.ejb.EJB”%>

<%

float result = 0;

try{
​ IntialContext ic = new InitialContext();

​ CalculatorBeanRemote calculator =(CalculatorBeanRemote)
ic.lookup(“java:global/addition/CalculatorBean!com.add.CalculatorBeanRemote”);

System.out.println(“Loaded Calculator Bean”);

String s1 = request.getParameter(“num1”);
String s2 = request.getParamter(“num2”);
String s3 = request.getParamter(“num3”);

System.out.println(s3);

if(s1!=null&& s2!=null){
​ float num1 = new float(s1);
​ floatnum2=new float(s2);

​ if(s3.equals(“add”))
​ result=calculator.add(num1.floatvalue(), num2.floatvalue());
%>
<p>

<b>The result is:</b> <%= result %>


<p>

<%
}
}// end of try
catch(exception e){
e.printStackTrace();
//result = “Not valid”;
}
%>

Output

You might also like