tag lib

Status
Nicht offen für weitere Antworten.

butalive

Mitglied
ich hab eine taglib geschrieben, bei der, wenn der tag <ergebnis operation="blabal"> angegeben wird, auch blabla ausgegeben wird.
es funktioniert also.

wenn ich aber jetzt
<ergebnis operation="h:mm a"> angebe
und in meiner classe bzw. java datei
Code:
Date dt = new Date();
private String operation;	
SimpleDateFormat df = new SimpleDateFormat(operation);
angebe funktioniert die ausgabe nicht mehr und ich bekomme die fehlermeldung

The server encountered an internal error () that prevented it from fulfilling this request.


mfg martin
 

The_S

Top Contributor
Also zum einen bist du im Falschen Forum. Das gehört in J2EE. Zum Anderen sagt dein Code rein gar nichts aus :lol: . Zeig doch mal deine komplette TagLib-Klasse, den dazugehörigen tld und eine Beispiel-JSP, die das Ganze implementiert.
 

butalive

Mitglied
hi hier mal der code von der tag lib datei util.tld
Code:
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
	version="2.0">
	<tlib-version>1.0</tlib-version>
	<jsp-version>1.2</jsp-version>
	<short-name>util</short-name>
	<uri>/util</uri>
	<description></description>	
	<tag>
		<name>ergebnis</name>
		<tag-class>tag.Datum</tag-class>
		<description>Operationsart</description>
		<attribute>
			<name>operation</name>
			<required>true</required>
		</attribute>
	</tag>
</taglib>

hier der code zur bsp. jsp
Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/util" prefix="util"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hallo</title>
</head>
<body>


Datum <util:ergebnis operation="h:mm a"/> .</p>
</body>
</html>

und zum schluß die classe
Code:
package tag;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.*;
import java.text.*;

@SuppressWarnings("serial")
public class Datum extends TagSupport {
//	 Tag ergebnis hat Attribut operation f. opart
	// (Variablendeklaration)
	Date dt = new Date();
	private String operation;	
	SimpleDateFormat df = new SimpleDateFormat(operation);	
	private int zahl1 = 0;
	private int zahl2 = 0;
	private int ergebnis = 0;

	public int doStartTag() throws JspException {
		try {
			String output = df.format( dt );
			JspWriter out = pageContext.getOut();			
			//pageContext.getSession().setAttribute("ZAHL", output);
			out.println(output);
			//out.println(operation); //nur zur überprüfung
		} catch (IOException e) {
			e.printStackTrace();
			throw new JspException("IOException: " + e.getMessage());
		}
		return SKIP_BODY;
	}

	// SET-Methode für 'operation' --> opart Zahl
	public void setOperation(String operation) {
		this.operation = operation;
	}

	

}
mfg martin
 

The_S

Top Contributor
mach hieraus
Code:
SimpleDateFormat df = new SimpleDateFormat(operation);

das hier

Code:
SimpleDateFormat df = null

und schreib das hier

Code:
df = new SimpleDateFormat(operation);

als erstes in deinen doStartTag.
 

The_S

Top Contributor
das musst du nicht, aber du erzeugst ein neues SimpleDateFormat objekt mit einer Variablen, die zu diesem Zeitpunkt noch nicht existiert.
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Oben