refactor project structure
This commit is contained in:
27
src/main/java/org/example/demo/HelloServlet.java
Executable file
27
src/main/java/org/example/demo/HelloServlet.java
Executable 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() {
|
||||
}
|
||||
}
|
||||
27
src/main/java/org/example/demo/beans/StudentBean.java
Executable file
27
src/main/java/org/example/demo/beans/StudentBean.java
Executable 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";
|
||||
}
|
||||
}
|
||||
|
||||
78
src/main/java/org/example/demo/models/Buch.java
Executable file
78
src/main/java/org/example/demo/models/Buch.java
Executable 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
|
||||
53
src/main/java/org/example/demo/models/BuchContainer.java
Executable file
53
src/main/java/org/example/demo/models/BuchContainer.java
Executable 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
|
||||
|
||||
6
src/main/resources/META-INF/beans.xml
Executable file
6
src/main/resources/META-INF/beans.xml
Executable 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>
|
||||
9
src/main/resources/META-INF/persistence.xml
Executable file
9
src/main/resources/META-INF/persistence.xml
Executable 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>
|
||||
7
src/main/webapp/WEB-INF/faces-config.xml
Executable file
7
src/main/webapp/WEB-INF/faces-config.xml
Executable 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
15
src/main/webapp/WEB-INF/web.xml
Executable 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
12
src/main/webapp/index.jsp
Executable 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>
|
||||
15
src/main/webapp/praktikum1/books/edit.jsp
Executable file
15
src/main/webapp/praktikum1/books/edit.jsp
Executable 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>
|
||||
31
src/main/webapp/praktikum1/books/index.jsp
Executable file
31
src/main/webapp/praktikum1/books/index.jsp
Executable 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>
|
||||
11
src/main/webapp/praktikum3/page1.xhtml
Executable file
11
src/main/webapp/praktikum3/page1.xhtml
Executable 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>
|
||||
24
src/main/webapp/uebung3/eingabe.xhtml
Executable file
24
src/main/webapp/uebung3/eingabe.xhtml
Executable 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>
|
||||
Reference in New Issue
Block a user