Skip to content

Commit

Permalink
add lab3 jsp
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkie20 committed Apr 1, 2024
1 parent 4eb91c0 commit fed991d
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lab2/exercise/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="UTF-8" />
<title>Simple HTML</title>
<title>Lab 2 Exercise</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet"
Expand Down
23 changes: 23 additions & 0 deletions Lab3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Maven specific files
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.branch
release.properties
maven-metadata-*.xml
maven-archiver/
MANIFEST.MF

# IntelliJ IDEA files
.idea/
*.iml

# Eclipse files
.classpath
.project
.settings/

# NetBeans files
nb-configuration.xml
build/
nbactions.xml
3 changes: 3 additions & 0 deletions Lab3/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
35 changes: 35 additions & 0 deletions Lab3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Lab3 Project

This project is a small web application built using Java Servlets and JSP with Spring Boot framework. Maven is used for dependency management and project build.
As Spring boot framework already contains TomCat Server, no more further download needed.

## Prerequisites

Before you begin, ensure you have the following installed on your machine:

- Java Development Kit (JDK) 8 or later
- Apache Maven
- Your favorite Java IDE or text editor

## Getting Started

To get started with this project, follow these steps:

1. Clone or download this repository to your local machine.

2. Navigate to the project directory.

3. Build the project using Maven:

```bash
mvn clean package

```
This command will compile the source code, run tests, and package everything into a JAR file located in the target/ directory.

4. Run the application
```bash
mvn spring-boot:run
```

5. Once the application is running, open your web browser and visit http://localhost:8080 to view the application.
91 changes: 91 additions & 0 deletions Lab3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.10</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>lab3</groupId>
<artifactId>app</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>10.1.18</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>3.2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0-M2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.0.0</version>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
</project>
13 changes: 13 additions & 0 deletions Lab3/src/main/java/lab3/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package lab3;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class App {

public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
29 changes: 29 additions & 0 deletions Lab3/src/main/java/lab3/controllers/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package lab3.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import jakarta.servlet.http.HttpServletRequest;


@Controller
public class HomeController {
@GetMapping("/")
public String home() {
return "WEB-INF/views/index.jsp";
}

@PostMapping("/results")
public String getThreeParams(HttpServletRequest request) {
String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");
String param3 = request.getParameter("param3");
request.setAttribute("param1", param1);
request.setAttribute("param2", param2);
request.setAttribute("param3", param3);

return "forward:/WEB-INF/views/result.jsp";
}


}
31 changes: 31 additions & 0 deletions Lab3/src/main/webapp/WEB-INF/views/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Get Three Parameters</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="flex justify-center items-center h-screen">
<div class="w-full max-w-md p-6 bg-white rounded-lg shadow-md">
<h2 class="text-2xl font-bold mb-4 text-center">Collect three parameters</h2>
<form action="/results" method="post">
<div class="mb-4">
<label for="param1" class="block font-bold">First Parameter:</label>
<input type="text" id="param1" name="param1" required placeholder="First parameter here..." class="w-full border-gray-300 rounded-md pl-2">
</div>
<div class="mb-4">
<label for="param2" class="block font-bold">Second Parameter:</label>
<input type="text" id="param2" name="param2" required placeholder="Second parameter here..." class="w-full border-solid border-black rounded-md pl-2">
</div>
<div class="mb-4">
<label for="param3" class="block font-bold">Third Parameter:</label>
<input type="text" id="param3" name="param3" required placeholder="Third parameter here..." class="w-full border-gray-300 rounded-md pl-2">
</div>
<div class="w-full flex justify-center">
<input type="submit" value="Submit" class="px-4 py-2 bg-blue-500 text-white rounded-md cursor-pointer">
</div>
</form>
</div>
</body>
</html>
39 changes: 39 additions & 0 deletions Lab3/src/main/webapp/WEB-INF/views/result.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<script src="https://cdn.tailwindcss.com"></script>
<title>Set Three Parameters</title>
</head>

<body class="flex justify-center items-center h-screen">
<div class="w-full max-w-md p-6 bg-white rounded-lg shadow-md">
<h2 class="text-2xl font-bold mb-4 text-center">Result Page</h2>
<table>
<tr>
<td><strong>First Parameter:</strong></td>
<td class="pl-2"><%= request.getAttribute("param1") %></td>
</tr>
<tr>
<td><strong>Second Parameter:</strong></td>
<td class="pl-2"><%= request.getAttribute("param2") %></td>
</tr>
<tr>
<td><strong>Third Parameter:</strong></td>
<td class="pl-2"><%= request.getAttribute("param3") %></td>
</tr>
</table>
<div class="w-full flex justify-center">
<a href="${pageContext.request.contextPath}/" class="block mt-4">
<button class="w-full bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Try new input!
</button>
</a>
</div>

</div>
</body>

</html>

0 comments on commit fed991d

Please sign in to comment.