rendered paste body---- WICHTIG !!!!!! ----
WER ZU BLÖD IST DAS ZEUG GENUG ZU ÄNDERN UND DENKT ER KANN DAS 1 zu 1 ÜBERNEHMEN OHNE AUFZUFLIEGEN MUSS EXTREM SEHR BESCHEUERT SEIN (hallo tobi)
UND SOLLTE ES EINFACH LASSEN. SONST KRIEG ICH WIEDER ÄRGER WORAUF ICH KEINEN BOCK HABE!!!
ALSO -> ÄNDERN SONST TOD!!!
P.S: Der folgende Source ist NICHT für tobi weil er einfach nur viel zu dumm is und denkt ernsthaft er kann das zeug unverändert abgeben... ich mein WIE DUMM KANN MAN SEIN TOBI!??!!??
Die Aufgaben 3 und 4 werden mit ProjektName/param (Aufgabe 3) bzw. ProjektName/firmen (Aufgabe 4) aufgerufen!
------- DATEI: Ausgabe.java
------- PACKAGE: servlet.tags
package servlet.tags;
import java.io.IOException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class Ausgabe extends TagSupport {
public int doStartTag()
{
return this.EVAL_PAGE;
}
public int doEndTag() throws JspTagException
{
try
{
pageContext.getOut().write("Viel Glück bei der MUK-Klausur!!!");
}
catch(IOException e)
{
e.printStackTrace();
}
return EVAL_PAGE;
}
}
------- DATEI ENDE
------- DATEI: Formular.java
------- PACKAGE: servlet.tags
package servlet.tags;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Formular extends HttpServlet {
Vector<String> firmennamen = new Vector<String>();
public void init()
{
Enumeration e = this.getInitParameterNames();
while(e.hasMoreElements())
{
String firma = (String) e.nextElement();
String firmaValue = this.getInitParameter(firma);
if(firmaValue != null)
firmennamen.addElement(firmaValue);
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><head><title>Aufgabe 4</title></head>");
out.println("<body>");
out.println("<form action='firmen' method='post'>");
out.println("<p>Firmenname<input type='text' name = 'firmenname'/></p>");
out.println("<input type='submit' value='Abschicken' />");
out.println("</form>");
out.println("</body></html>");
}
public void doPost (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String eingabe = req.getParameter("firmenname");
out.println("Eingabe: "+eingabe+"<br/>");
boolean hasFirmaGefunden = false;
for(int i=0;i<firmennamen.size();i++)
{
String firma = firmennamen.elementAt(i);
if(firma.equalsIgnoreCase(eingabe))
{
hasFirmaGefunden = true;
}
}
if(hasFirmaGefunden)
out.println("Firma gefunden!");
else
out.println("Firma NICHT gefunden!");
}
}
------- DATEI ENDE
------- DATEI: IfConditionTag.java
------- PACKAGE: servlet.tags
package servlet.tags;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class IfConditionTag extends BodyTagSupport {
public int doAfterBody()
{
IfTag parent = (IfTag) this.findAncestorWithClass(this, IfTag.class);
Lotto parentFromIf = (Lotto) parent.findAncestorWithClass(parent, Lotto.class);
if(parent == null)
{
// Fehler
}
else
{
parent.setCondition(Integer.parseInt(this.getBodyContent().getString()));
}
return this.SKIP_BODY;
}
public int doStartTag()
{
IfTag parent = (IfTag) this.findAncestorWithClass(this, IfTag.class);
if(parent == null)
{
// Fehler
}
return this.EVAL_BODY_BUFFERED;
}
}
------- DATEI ENDE
------- DATEI: IfElseTag.java
------- PACKAGE: servlet.tags
package servlet.tags;
import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class IfElseTag extends BodyTagSupport {
public int doStartTag()
{
IfTag parent = (IfTag) this.findAncestorWithClass(this, IfTag.class);
if(parent == null)
{
// Fehler
}
else
{
if(!parent.getHasCondition())
{
// Fehler, keine Condition gesetzt
}
else
{
if(!(parent.getCondition() >= 1 && parent.getCondition() <= 49))
{
JspWriter out = pageContext.getOut();
try {
out.println("Zahl "+parent.getCondition()+" ungültig!<br/>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
return this.SKIP_BODY;
}
}
return this.SKIP_BODY;
}
public int doAfterBody()
{
return this.EVAL_BODY_INCLUDE;
}
}
------- DATEI ENDE
------- DATEI: IfTag.java
------- PACKAGE: servlet.tags
package servlet.tags;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class IfTag extends BodyTagSupport {
private int condition;
private boolean hasCondition = false;
public int doStartTag()
{
return this.EVAL_BODY_INCLUDE;
}
public int doAfterBody()
{
return this.SKIP_BODY;
}
public boolean getHasCondition()
{
return hasCondition;
}
public int getCondition()
{
return condition;
}
public void setCondition(int condition)
{
hasCondition = true;
this.condition = condition;
}
}
------- DATEI ENDE
------- DATEI: IfThenTag.java
------- PACKAGE: servlet.tags
package servlet.tags;
import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class IfThenTag extends BodyTagSupport {
public int doStartTag()
{
IfTag parent = (IfTag) this.findAncestorWithClass(this, IfTag.class);
Lotto parentFromIf = (Lotto) parent.findAncestorWithClass(parent, Lotto.class);
if(parent == null)
{
// Fehler
}
else
{
if(!parent.getHasCondition())
{
// Fehler, keine Condition gesetzt
}
else
{
if(parent.getCondition() >= 1 && parent.getCondition() <= 49)
{
parentFromIf.setNeueZahl(parent.getCondition());
JspWriter out = pageContext.getOut();
try {
out.println("Zahl "+parent.getCondition()+" gültig!<br/>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
return this.SKIP_BODY;
}
}
return this.SKIP_BODY;
}
public int doAfterBody()
{
return this.EVAL_BODY_INCLUDE;
}
}
------- DATEI ENDE
------- DATEI: Lotto.java
------- PACKAGE: servlet.tags
package servlet.tags;
import java.io.IOException;
import java.util.Vector;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class Lotto extends BodyTagSupport {
boolean repeat = true;
Vector<Integer> zahlen = new Vector<Integer>();
public int doStartTag()
{
return this.EVAL_BODY_INCLUDE;
}
public void setNeueZahl(int zahl)
{
zahlen.addElement(zahl);
if(zahlen.size()>= 6)
repeat = false;
}
public int doAfterBody()
{
if(repeat)
return this.EVAL_BODY_AGAIN;
else
{
JspWriter out = pageContext.getOut();
try {
out.println("<br/><br/>Gefundene Zahlen:<br/><br/>");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
for(int i=0;i<zahlen.size();i++)
{
try {
out.println("Zahl "+(i+1)+": "+zahlen.elementAt(i)+"<br/>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return this.SKIP_BODY;
}
}
}
------- DATEI ENDE
------- DATEI: Param.java
------- PACKAGE: servlet.tags
package servlet.tags;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Param extends HttpServlet {
Vector<String> initParameterValue = new Vector<String>();
Vector<String> initParameterNames = new Vector<String>();
public void init() throws ServletException
{
Enumeration e = this.getInitParameterNames();
while(e.hasMoreElements())
{
String initParam = (String) e.nextElement();
String initParamValue = this.getInitParameter(initParam);
if(initParamValue != null)
{
initParameterValue.addElement(initParamValue);
initParameterNames.addElement(initParam);
}
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
for(int i=0;i<initParameterNames.size();i++)
{
out.println("Parameter "+(i+1)+": NAME="+initParameterNames.elementAt(i)+
" - VALUE="+initParameterValue.elementAt(i)+"<br/>");
}
}
}
------- DATEI ENDE
------- DATEI: taglib.tld
------- PFAD: WEB-INF/lib
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>mybib</shortname>
<info>OReilly Sample Tag library</info>
<tag>
<name>Ausgabe</name>
<tagclass>servlet.tags.Ausgabe</tagclass>
<info>Klausur 3 - Aufgabe 1</info>
<bodycontent>JSP</bodycontent>
</tag>
<tag>
<name>Lotto</name>
<tagclass>servlet.tags.Lotto</tagclass>
<info>Klausur 3 - Aufgabe 2</info>
<bodycontent>JSP</bodycontent>
</tag>
<tag>
<name>MyFont</name>
<tagclass>servlet.tags.MyFont</tagclass>
<info>MyFont-Tag</info>
<bodycontent>JSP</bodycontent>
<attribute>
<name>font</name>
<required>true</required>
</attribute>
<info>
</info>
</tag>
<tag>
<name>if</name>
<tagclass>servlet.tags.IfTag</tagclass>
<info>If-Tag</info>
<bodycontent>JSP</bodycontent>
<info>
</info>
</tag>
<tag>
<name>condition</name>
<tagclass>servlet.tags.IfConditionTag</tagclass>
<info>If-Condition-Tag</info>
<bodycontent>JSP</bodycontent>
<info>
</info>
</tag>
<tag>
<name>then</name>
<tagclass>servlet.tags.IfThenTag</tagclass>
<info>If-Then-Tag</info>
<bodycontent>JSP</bodycontent>
<info>
</info>
</tag>
<tag>
<name>else</name>
<tagclass>servlet.tags.IfElseTag</tagclass>
<info>If-Else-Tag</info>
<bodycontent>JSP</bodycontent>
<info>
</info>
</tag>
<tag>
<name>repeat</name>
<tagclass>servlet.tags.RepeatTag</tagclass>
<info>If-Condition-Tag</info>
<bodycontent>JSP</bodycontent>
<attribute>
<name>reps</name>
<required>true</required>
</attribute>
<info>
</info>
</tag>
</taglib>
------- DATEI ENDE
------- DATEI: web.xml
------- PFAD: WEB-INF
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<web-app>
<taglib>
<taglib-uri>http://xmlguru.de/jct</taglib-uri>
<taglib-location>/WEB-INF/tags.tld</taglib-location>
</taglib>
<servlet>
<servlet-name>firmen</servlet-name>
<servlet-class>servlet.tags.Formular</servlet-class>
<init-param>
<param-name>
Firma1
</param-name>
<param-value>
ADV
</param-value>
</init-param>
<init-param>
<param-name>
Firma2
</param-name>
<param-value>
BDV
</param-value>
</init-param>
<init-param>
<param-name>
Firma3
</param-name>
<param-value>
CDV
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>firmen</servlet-name>
<url-pattern>/firmen</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>param</servlet-name>
<servlet-class>servlet.tags.Param</servlet-class>
<init-param>
<param-name>
Firmenname
</param-name>
<param-value>
ADV
</param-value>
</init-param>
<init-param>
<param-name>
Firmenbezeichnung
</param-name>
<param-value>
Softwareentwickler
</param-value>
</init-param>
<init-param>
<param-name>
Firmenvorsitzender
</param-name>
<param-value>
Michael Bessert
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>param</servlet-name>
<url-pattern>/param</url-pattern>
</servlet-mapping>
</web-app>
------- DATEI ENDE
------- DATEI: aufgabe1.jsp
------- PFAD: /
<html>
<head><title>Test</title></head>
<body>
<%@ taglib uri="WEB-INF/lib/taglib.tld" prefix="mybib" %>
<mybib:Ausgabe></mybib:Ausgabe>
</body>
</html>
------- DATEI ENDE
------- DATEI: aufgabe2.jsp
------- PFAD: /
<html>
<head><title>Test 2</title></head>
<body>
<%@ taglib uri="WEB-INF/lib/taglib.tld" prefix="mybib" %>
<mybib:Lotto>
<mybib:if>
<mybib:condition><%= (int)(Math.random() * 100) %></mybib:condition>
<mybib:then></mybib:then>
<mybib:else></mybib:else>
</mybib:if>
</mybib:Lotto>
</body>
</html>
------- DATEI ENDE