~ small fixes
- db, hello
- web.xml

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2019-04-27 11:37:05 +02:00
parent 5849812afd
commit 027ebd2a46
8 changed files with 26 additions and 167 deletions

View File

@ -97,30 +97,6 @@ public class Database {
return null;
}
/**
* testing method.
*
* @return String
*/
@Deprecated
public String getHello() {
Connection connection = getConnection();
String hello = "";
try {
assert connection != null;
PreparedStatement statement = connection.prepareStatement("SELECT * FROM test WHERE id = 1");
ResultSet resultSet = statement.executeQuery();
if (resultSet.next())
hello = resultSet.getString("hello");
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
return hello;
}
/**
* gets author by id.
*

View File

@ -1,5 +1,6 @@
package de.hsel.itech.servlet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -14,6 +15,8 @@ import java.io.PrintWriter;
* @version 0.1
* @since 0.1
*/
@WebServlet("/addbook")
public class AddBook extends HttpServlet {

View File

@ -6,6 +6,7 @@ import de.hsel.itech.db.pojo.Book;
import de.hsel.itech.db.pojo.Category;
import de.hsel.itech.db.pojo.Publisher;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -24,6 +25,8 @@ import java.util.List;
* @version 0.1
* @since 0.1
*/
@WebServlet("/booklist")
public class BookList extends HttpServlet {
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
@ -92,8 +95,7 @@ public class BookList extends HttpServlet {
for (String name : authorNames) {
authors.add(new Author(name));
}
Category category = new Category();
category.setName(categoryName);
Category category = new Category(categoryName);
Book book = new Book(isbn,
authors,
new Publisher(publisher),
@ -133,10 +135,13 @@ public class BookList extends HttpServlet {
out.println("<h2>" + book.getTitle() + "</h2>");
out.println("ISBN: " + book.getIsbn() + "</br>");
for (int i = 0; i < book.getAuthors().size(); i++) {
out.println("von " + book.getAuthors().get(0).getName());
List<String> authors = new ArrayList<>();
for(Author author : book.getAuthors()) {
authors.add(author.getName());
}
out.println("von: " + String.join(", ", authors));
out.println("</br>Veröffentlicht von " + book.getPublisher().getName() + "");
out.println("</br></br>" + book.getDescription() + "");

View File

@ -1,44 +0,0 @@
package de.hsel.itech.servlet;
import de.hsel.itech.db.Database;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Database test.
*
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
public class DbTest extends HttpServlet {
private static final long serialVersionUID = 15679036734L;
/**
* doGet.
*
* @param req Request
* @param resp Response
* @throws IOException failed
*/
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html");
final PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hallo Welt!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>" + Database.getInstance().getHello() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}

View File

@ -1,46 +0,0 @@
package de.hsel.itech.servlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Hello World.
*
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 15679036735L;
/**
* doGet.
*
* @param req Request
* @param resp Response
* @throws IOException failed
*/
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html");
final PrintWriter out = resp.getWriter();
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Hallo Welt!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hallo Ostfriesland!</h1><br>");
out.println("<h3>" + System.getProperty("catalina.base") + "</h3><br>");
out.println("<h4>" + new File("").getAbsolutePath() + "</h4>");
out.println("</body>");
out.println("</html>");
}
}

View File

@ -28,9 +28,9 @@
</ul>
</div>
<div class="m-col-s-3 m-col-t-6">
<h3><a href="#">Rechtliches</a></h3>
<h3>Rechtliches</h3>
<ul>
<li><a href="https://joethei.xyz/impress">Impressum</a></li>
<li><a href="https://joethei.xyz/imprint">Impressum</a></li>
<li><a href="https://joethei.xyz/privacy">Datenschutz</a></li>
<li><a href="https://joethei.xyz/disclaimer">Haftung</a></li>
</ul>

View File

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>helloWorld</servlet-name>
<servlet-class>de.hsel.itech.servlet.HelloWorld</servlet-class>
</servlet>
<servlet>
<servlet-name>database</servlet-name>
<servlet-class>de.hsel.itech.servlet.DbTest</servlet-class>
</servlet>
<servlet>
<servlet-name>booklist</servlet-name>
<servlet-class>de.hsel.itech.servlet.BookList</servlet-class>
</servlet>
<servlet>
<servlet-name>addbook</servlet-name>
<servlet-class>de.hsel.itech.servlet.AddBook</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloWorld</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>database</servlet-name>
<url-pattern>/db</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>booklist</servlet-name>
<url-pattern>/booklist</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>addbook</servlet-name>
<url-pattern>/addbook</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="de">
<head>
<title>Internet Technologien</title>
</head>
<body>
<ul>
<li><a href="preview">Grobspezifikation</a></li>
<li><a href="booklist">Backend</a></li>
</ul>
</body>
</html>