Skip to content
Snippets Groups Projects
Commit 8428495b authored by Wqrld's avatar Wqrld
Browse files

Initial bookquote app

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #60443 failed
target/
.DS_Store
.idea/
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<groupId>nl.utwente.di</groupId>
<artifactId>bookQuote</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package nl.utwente.di.bookQuote;
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
/** Example of a Servlet that gets an ISBN number and returns the book price
*/
public class BookQuote extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
private Quoter quoter;
public void init() throws ServletException {
quoter = new Quoter();
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Book Quote";
// Done with string concatenation only for the demo
// Not expected to be done like this in the project
out.println("<!DOCTYPE HTML>\n" +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE>" +
"<LINK REL=STYLESHEET HREF=\"styles.css\">" +
"</HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>" + title + "</H1>\n" +
" <P>ISBN number: " +
request.getParameter("isbn") + "\n" +
" <P>Price: " +
quoter.getBookPrice(request.getParameter("isbn")) +
"</BODY></HTML>");
}
}
package nl.utwente.di.bookQuote;
import java.util.HashMap;
public class Quoter {
HashMap<String, Double> books;
public Quoter() {
books = new HashMap<>();
books.put("1", 10.0);
books.put("2", 45.0);
books.put("3", 20.0);
books.put("4", 35.0);
books.put("5", 50.0);
}
public double getBookPrice(String isbn) {
return books.getOrDefault(isbn, 0.0);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
<display-name>di.bookQuote</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>BookQuote Servlet</description>
<display-name>BookQuote</display-name>
<servlet-name>BookQuote</servlet-name>
<servlet-class>nl.utwente.di.bookQuote.BookQuote</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BookQuote</servlet-name>
<url-pattern>/bookQuote</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
<!DOCTYPE HTML>
<!-- Front end for the webBookQuote Servlet. -->
<html lang="en">
<head>
<title>Web Book Quote Application</title>
<link rel="stylesheet" href="styles.css">
<meta charset="UTF-8">
</head>
<body>
<h1>Web Book Quote Application</h1>
<form ACTION="./bookQuote">
<p>Enter ISBN number: <input TYPE="TEXT" NAME="isbn"></p>
<input TYPE="SUBMIT">
</form>
</body>
</html>
BODY { background-color: WHITE }
H1 { color: PURPLE;
text-align: left;
font-size: 28px;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal
}
.LARGER { font-size: 120% }
.TINY { font-size: 50% }
H2 { color: #440000;
text-align: left;
font-family: Arial, Helvetica, sans-serif
}
H3 { color: #440000;
text-align: left;
font-family: Arial, Helvetica, sans-serif
}
UL { margin-top: 0;
border-top-width: 0;
padding-top: 0
}
P { color: BLACK;
text-align: left;
font-size: 20px;
font-family: Arial, Helvetica, sans-serif
}
FORM { color: BLACK;
text-align: left;
font-size: 20px;
font-family: Arial, Helvetica, sans-serif
}
PRE { font-size: 105%;
}
CODE { font-size: 105%;
}
.TOC { font-size: 90%;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif
}
TH.COLORED { background-color: #FFAD00
}
TR.COLORED { background-color: #FFAD00
}
TH.TITLE { background-color: #EF8429;
font-size: 40px;
font-family: Arial, Helvetica, sans-serif;
}
A:hover { color: red }
package nl.utwente.di.bookQuote;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class TestQuoter {
@Test
public void testBook1() throws Exception {
Quoter quoter = new Quoter();
double price = quoter.getBookPrice("1");
Assertions.assertEquals(10.0, price, 0.0, "Price of book 1");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment