HI
Ich habe eine Kleine Web Anwendung zur Übung Geschrieben, nun bin ich dabei alles von JSP mit Java Code zu JSP mit JSTL umzustellen.
Mein Katalog meines kleinen Buchshops funktioniert soweit mit JSTL nur wenn ich nun vom Katalog zum Warenkorb Wechsel findet das JSP die Java Methoden nicht
Mein Warenkorb.jsp
Mein Controller
ich weiß mein Warenkorb kommt mindestens bis zum Controller. Fehler sind wenn entweder Zwischen Controller oder direckt im JSP
der StackTrace verräht mir das im JSP zeile 20 der Fehler ist. Das Property welches nicht gefunden wird ist eine Methode aus der Java Klasse Warenkorb, was aber nicht sein kann da vorher alles funktionierte erst bei der umstellung von Java zu JSTL im JSP funktioniert es nicht mehr.
die Java Klasse Warenkorb spare ich mir vorerst da ich vermute das das Warenkorb Objekt nicht ordnugsgemäß übergeben wird. Aber ich weiß nicht was ich falsch mache
Ich habe eine Kleine Web Anwendung zur Übung Geschrieben, nun bin ich dabei alles von JSP mit Java Code zu JSP mit JSTL umzustellen.
Mein Katalog meines kleinen Buchshops funktioniert soweit mit JSTL nur wenn ich nun vom Katalog zum Warenkorb Wechsel findet das JSP die Java Methoden nicht

Mein Warenkorb.jsp
HTML:
<jsp:useBean id="warenkorb" scope="session" class="model.Warenkorb" />
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="model.*,java.text.DecimalFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="controler.ControllerAction"%><html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Warenkorb.jsp</title>
</head>
<body>
<%@ include file="/view/Banner.jsp"%>
<c:set var="warenkorb" value="${sessionScope.warenkorb}"/>
<em>Es befinden sich <c:out value="${warenkorb.anzahlbuecher}"></c:out> Elemente im Warenkorb.</em>
<br />
<br />
<table>
<tr>
<th colspan="4">Warenkorb</th>
</tr>
<c:forEach items="${warenkorb.warenkorbelemente}" var="element">
<tr>
<td>
${element.anzahl}
x</td>
<td>
${element.buch.autor}
</td>
<td><a
href="Controller?action=<%=ControllerAction.BUCH_ANZEIGEN.getAction()%>&isbn=
${element.buch.isbn}">
${element.buch.buch}
</a></td>
<td>
${element.gesamtpreis}
€</td>
<td><a
href="Controller?action=<%=ControllerAction.BUCH_HERAUSNEHMEN.getAction()%>&isbn=${element.buch.isbn}">
Buch löschen </a></td>
</tr>
</c:forEach>
<tr>
<td colspan="3"><strong>Gesamtpreis</strong></td>
<td>
${warenkorb.gesamtpreis})
€</td>
</tr>
</table>
<a href="Controller?action=<%=ControllerAction.KATALOG_ANZEIGEN.getAction()%>"> «
zurück zum Katalog </a>
<a href="Controller?action=<%=ControllerAction.BUCH_BESTELLEN.getAction()%>"> Bücher
bestellen → </a>
</body>
</html>
Code:
package controler;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.Buch;
import model.Katalog;
import model.Warenkorb;
/**
* Servlet implementation class BuchladenServlet
*/
public class Controller extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 58268476537320082L;
public static String KATALOG = "web.model.Katalog";
public static String WAHRENKORB = "web.model.Warenkorb";
private Katalog katalog;
private Warenkorb warenkorb;
private Buch buch;
private RequestDispatcher requestDispatcher;
private HttpSession httpSession;
private HttpServletRequest request;
private HttpServletResponse response;
private ServletContext context;
/**
* @see HttpServlet#HttpServlet()
*/
public Controller() {
super();
}
public void init() {
}
public void destroy() {
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
this.request = request;
this.response = response;
this.httpSession = this.request.getSession();
this.context = getServletContext();
this.warenkorb = (Warenkorb) this.httpSession.getAttribute("warenkorb");
if (warenkorb == null) {
this.warenkorb = new Warenkorb();
this.httpSession.setAttribute("warenkorb", warenkorb);
}
this.katalog = (Katalog) this.context.getAttribute("katalog");
if (katalog == null) {
this.katalog = Katalog.erzeuge();
this.context.setAttribute("katalog", katalog);
}
String actionParameter = request.getParameter("action");
ControllerAction action = getAction(actionParameter);
String isbn = request.getParameter("isbn");
switch (action) {
case KATALOG_ANZEIGEN:
default:
katalogAnzeigen();
break;
case BUCH_ANZEIGEN:
zeigeBuchInfoAn(isbn);
break;
case BUCH_HINZUFUEGEN:
fuegeBuchinWarenkorbHinzu(isbn);
break;
case BUCH_HERAUSNEHMEN:
nehmeBuchAusWarenkorbHeraus(isbn);
break;
case WARENKORB_ANZEIGEN:
warenkorbAnzeigen();
break;
case BUCH_BESTELLEN:
bestellungabschicken();
break;
}
}
private void bestellungabschicken() throws ServletException, IOException {
request.setAttribute("warenkorbElemente", warenkorb
.getWarenkorbElemente());
forwardTo("/Bestellen");
}
/**
* @throws IOException
* @throws ServletException
*
*/
private void katalogAnzeigen() throws ServletException, IOException {
request.setAttribute("katalogBuecher", katalog.getAlleBuecher());
forwardTo("/Katalog");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
}
private void zeigeBuchInfoAn(String isbn) throws ServletException, IOException {
buch = katalog.getBuchInfo(isbn);
request.setAttribute("buch", buch);
forwardTo("/Buch");
}
private void fuegeBuchinWarenkorbHinzu(String isbn)
throws ServletException, IOException {
buch = katalog.getBuchInfo(isbn);
warenkorb.setWarenkorbElement(buch.getIsbn(), buch);
httpSession.setAttribute("warenkorb", warenkorb);
request.setAttribute("buch", buch);
request.setAttribute("katalogBuecher", katalog.getAlleBuecher());
forwardTo("/Katalog");
}
private void nehmeBuchAusWarenkorbHeraus(String isbn)
throws ServletException, IOException {
buch = katalog.getBuchInfo(isbn);
warenkorb.loescheWarenkorbElement(buch.getIsbn());
httpSession.setAttribute("warenkorb", warenkorb);
request.setAttribute("warenkorbElemente", warenkorb
.getWarenkorbElemente());
forwardTo("/Warenkorb");
}
private void warenkorbAnzeigen() throws ServletException, IOException {
httpSession.setAttribute("warenkorb", warenkorb);
request.setAttribute("warenkorbElemente", warenkorb.getWarenkorbElemente());
forwardTo("/Warenkorb");
}
private void forwardTo(String url) throws ServletException, IOException {
requestDispatcher = context.getRequestDispatcher(url);
requestDispatcher.forward(request, response);
}
/**
* @param actionParameter
* @return
*/
private ControllerAction getAction(String actionParameter) {
ControllerAction action = ControllerAction.KATALOG_ANZEIGEN;;
if (actionParameter != null)
for (ControllerAction act : ControllerAction.values()) {
if (act.getAction().equals(actionParameter)){
action = act;
break;
// action = ControllerAction.valueOf(actionParameter);
}
}
return action;
}
}
der StackTrace verräht mir das im JSP zeile 20 der Fehler ist. Das Property welches nicht gefunden wird ist eine Methode aus der Java Klasse Warenkorb, was aber nicht sein kann da vorher alles funktionierte erst bei der umstellung von Java zu JSTL im JSP funktioniert es nicht mehr.
die Java Klasse Warenkorb spare ich mir vorerst da ich vermute das das Warenkorb Objekt nicht ordnugsgemäß übergeben wird. Aber ich weiß nicht was ich falsch mache
