Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Week 8 Assignment 1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Java files present in /Week 8 Assignment 1/src/com/greatlearning/servets
* Build in /Week 8 Assignment 1/build/classes/com/greatlearning/servets/
* Directly download "week8" and place in Drive:\apache-tomcat-8.5.43\webapps\ and start the server "http://localhost:8080/week8/users"
3 changes: 3 additions & 0 deletions Week 8 Assignment 1/WebContent/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions Week 8 Assignment 1/WebContent/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Week 8 Assignment 1</display-name>
<servlet>
<servlet-name>userList</servlet-name>
<servlet-class>com.greatlearning.servets.ListUserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>userList</servlet-name>
<url-pattern>/users</url-pattern>
</servlet-mapping>
</web-app>
34 changes: 34 additions & 0 deletions Week 8 Assignment 1/WebContent/display.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" isELIgnored="false"%>
<%@page import="com.greatlearning.servets.User"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Users</title>
</head>
<body>
<table border="1" width="500" align="center">
<tr bgcolor="f0f0f0">
<th><b>User ID</b></th>
<th><b>User Name</b></th>
<th><b>User Age</b></th>
<th><b>User Location</b></th>
</tr>
<%
ArrayList<User> arrayList = (ArrayList<User>)request.getAttribute("name");
for(User user: arrayList) {%>
<tr>
<td><%= user.getId() %></td>
<td><%= user.getName() %></td>
<td><%= user.getAge() %></td>
<td><%= user.getLocation() %></td>
</tr>
<%}
%>
</table>
</body>
</html>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.greatlearning.servets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ListUserServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
ArrayList<User> userList = new ArrayList<User>();
userList.add(new User(1, "User1", 30, "Goa"));
userList.add(new User(5, "User2", 25, "Bangalore"));
userList.add(new User(3, "User3", 47, "Delhi"));
userList.add(new User(9, "User4", 24, "Mumbai"));

req.setAttribute("name", userList);
RequestDispatcher requestDispatcher = req.getRequestDispatcher("/display.jsp");
requestDispatcher.forward(req, res);
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
}
}
40 changes: 40 additions & 0 deletions Week 8 Assignment 1/src/com/greatlearning/servets/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.greatlearning.servets;

public class User {
private long id;
private String name;
private int age;
private String location;
public User(long id, String name, int age, String location) {
super();
this.id = id;
this.name = name;
this.age = age;
this.location = location;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}

}
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions Week 8 Assignment 1/week8/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Week 8 Assignment 1</display-name>
<servlet>
<servlet-name>userList</servlet-name>
<servlet-class>com.greatlearning.servets.ListUserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>userList</servlet-name>
<url-pattern>/users</url-pattern>
</servlet-mapping>
</web-app>
34 changes: 34 additions & 0 deletions Week 8 Assignment 1/week8/display.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" isELIgnored="false"%>
<%@page import="com.greatlearning.servets.User"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Users</title>
</head>
<body>
<table border="1" width="500" align="center">
<tr bgcolor="f0f0f0">
<th><b>User ID</b></th>
<th><b>User Name</b></th>
<th><b>User Age</b></th>
<th><b>User Location</b></th>
</tr>
<%
ArrayList<User> arrayList = (ArrayList<User>)request.getAttribute("name");
for(User user: arrayList) {%>
<tr>
<td><%= user.getId() %></td>
<td><%= user.getName() %></td>
<td><%= user.getAge() %></td>
<td><%= user.getLocation() %></td>
</tr>
<%}
%>
</table>
</body>
</html>