refactor project structure

This commit is contained in:
2025-11-13 12:14:07 +01:00
parent 00fad14ab5
commit a2bc018235
24 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package org.example.demo;
import java.io.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
private String message;
public void init() {
message = "Hello World!";
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
// Hello
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h1>" + message + "</h1>");
out.println("</body></html>");
}
public void destroy() {
}
}

View File

@@ -0,0 +1,27 @@
package org.example.demo.beans;
import jakarta.enterprise.context.SessionScoped;
import jakarta.inject.Named;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.io.Serializable;
@Named
@SessionScoped
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class StudentBean implements Serializable {
private String name;
private String matrikelnummer;
private String studiengang;
public String speichern() {
return "ausgabe?faces-redirect=true";
}
}

View File

@@ -0,0 +1,78 @@
package org.example.demo.models;
public class Buch
{
//Buch Attribute
private String titel;
private double preis;
private int id;
private static Integer idCounter;
//Konstruktor
static{
idCounter=0;
}
public Buch(String titel, double preis) {
super();
this.titel = titel;
this.preis = preis;
synchronized(this.getClass()){
id=idCounter;
idCounter++;
}
}// Konstruktor
public Buch() {
this("",-1);
}// Konstruktor
//Operation update(): aendert alle Attribute
public void update(String titel, double preis) {
this.titel = titel;
this.preis = preis;
}// update
public String getTitel() {
return titel;
}
public void setTitel(String titel) {
this.titel = titel;
}
public double getPreis() {
return preis;
}
public void setPreis(double preis) {
this.preis = preis;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String toString()
{
return this.titel+", "
+ ((""+preis).replace('.',','));
}// toString
public boolean equals(Object o){
if(o != null
&& o.getClass() == this.getClass()
&& ((Buch)o).getId()==this.getId()
){
return true;
}
else{
return false;
}
}
}// Buch

View File

@@ -0,0 +1,53 @@
package org.example.demo.models;
import java.util.ArrayList;
public class BuchContainer
{
//Objektverwaltung
private ArrayList<Buch> buchContainer;
public BuchContainer() {
buchContainer = new ArrayList<Buch>();
}// Konstruktor
//Operation add(): fuegt ein Element hinzu
public void add(Buch buch)
{
buchContainer.add(buch);
}// add
public void update(Buch buch, String titel, double preis) {
// Attribute des Buchs werden geaendert
buch.update(titel, preis);
}
//Operation delete(): loescht ein Buch aus dem Container
public void delete(Buch buch)
{
buchContainer.remove(buch);
}// delete
public void delete(int id)
{
Buch buch = new Buch();
buch.setId(id);
buchContainer.remove(buch);
}// delete
//
public Buch get(int id){
Buch buch = new Buch();
buch.setId(id);
return buchContainer.get(buchContainer.indexOf(buch));
}
//Rückgabe des Containers als Array von Objekten
public ArrayList<Buch> getAll()
{
return buchContainer;
}// getAll
}// class BuchContainer

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_4_1.xsd">
</beans>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_2.xsd"
version="3.2">
<persistence-unit name="default">
</persistence-unit>
</persistence>

View File

@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="4.0" 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-facesconfig_4_0.xsd" >
</faces-config>

15
src/main/webapp/WEB-INF/web.xml Executable file
View File

@@ -0,0 +1,15 @@
<?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">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>

12
src/main/webapp/index.jsp Executable file
View File

@@ -0,0 +1,12 @@
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>JSP - Hello World</title>
</head>
<body>
<h1><%= "Hello World!" %></h1>
<br/>
<a href="hello-servlet">Hello Servlet test</a>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<%--
Created by IntelliJ IDEA.
User: LinusNagel
Date: 17.10.2025
Time: 10:52
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,31 @@
<%--
Created by IntelliJ IDEA.
User: LinusNagel
Date: 17.10.2025
Time: 10:24
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<ul>
<%
// for (int i = 0; i < books.length; i++) {
%>
<li>
<%-- <%= books[i].name %>, <%= books[i].price %>--%>
<a href="./books/edit"> Bearbeiten</a>
<form >
<input type="button"/>
</form>
</li>
<%
// }
%>
</ul>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:outputLabel value="Hello, world"/>
</f:view>
</html>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Studentendaten</title>
</h:head>
<h:body>
<h:form>
<h:outputLabel for="name" value="Name:" />
<h:inputText id="name" value="#{studentBean.name}" /><br />
<h:outputLabel for="matrikel" value="Matrikelnummer:" />
<h:inputText id="matrikel" value="#{studentBean.matrikelnummer}" /><br />
<h:outputLabel for="studiengang" value="Studiengang:" />
<h:inputText id="studiengang" value="#{studentBean.studiengang}" /><br />
<h:commandButton value="Speichern" action="#{studentBean.speichern}" />
</h:form>
</h:body>
</html>