JSP Custom Tags -String[]
Hi,
my custom tag should use a String[] but I don�t know how to explain it in the attribute-type of the tld...
thanks for helping me
How about trying this...
<attribute>
<name>arrayAttribute</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String[]</type>
</attribute>
Simple eh? Too simple?
Good luck
evnafets
Similar Messages
-
Hi, can anyone advise as to whether my tag library code (based
on Apache Jakarta Project) will actually achieve connection
pooling functionality across my entire JSP based application? I
am slightly concerned that my OracleConnectionCacheImpl object
may exist multiple times, hence rendering my conection pooling
attempt useless.
package com.solved.tag.dbtags.connection;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspTagException;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import oracle.jdbc.pool.OracleConnectionCacheImpl;
* <p>JSP tag connection, used to get a
* java.sql.Connection object.</p>
* <p>JSP Tag Lib Descriptor
* <pre>
* <name>connection</name>
<tagclass>com.solved.tag.dbtags.connection.ConnectionTag</t
agclass>
* <bodycontent>JSP</bodycontent>
<teiclass>com.solved.tag.dbtags.connection.ConnectionTEI</t
eiclass>
* <info>Opens a connection based on a jndiName.</info>
* <attribute>
* <name>id</name>
* <required>true</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* </pre>
* @author Matt Shannon
public class ConnectionTag extends TagSupport {
static private OracleConnectionCacheImpl cache = null;
public int doStartTag() throws JspTagException {
try {
Connection conn = null;
if (cache == null) {
try {
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup
("jdbc/pool/OracleCache");
cache = (OracleConnectionCacheImpl)ds;
catch (NamingException ne) {
throw new JspTagException(ne.toString());
conn = cache.getConnection();
pageContext.setAttribute(getId(),conn);
catch (SQLException e) {
throw new JspTagException(e.toString());
return EVAL_BODY_INCLUDE;
package com.solved.tag.dbtags.connection;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.jsp.tagext.TagSupport;
* <p>JSP tag closeconnection, used to close the
* specified java.sql.Connection.<p>
* <p>JSP Tag Lib Descriptor
* <pre>
* <name>closeConnection</name>
<tagclass>com.solved.tag.dbtags.connection.CloseConnectionTag&
lt;/tagclass>
* <bodycontent>empty</bodycontent>
* <info>Close the specified connection. The "conn"
attribute is the name of a
* connection object in the page context.</info>
* <attribute>
* <name>conn</name>
* <required>true</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* </pre>
* @author Matt Shannon
* @see ConnectionTag
public class CloseConnectionTag extends TagSupport {
private String _connId = null;
* The "conn" attribute is the name of a
* page context object containing a
* java.sql.Connection.
* @param connectionId
* attribute name of the java.sql.Connection to
close.
* @see ConnectionTag
public void setConn(String connectionId) {
_connId = connectionId;
public int doStartTag() {
try {
Connection conn = (Connection)pageContext.getAttribute
(_connId);
conn.close();
} catch (SQLException e) {
// failing to close a connection is not fatal
e.printStackTrace();
return EVAL_BODY_INCLUDE;
public void release() {
_connId = null;
package com.solved.tag.dbtags.connection;
import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.VariableInfo;
* TagExtraInfo for the connection tag. This
* TagExtraInfo specifies that the ConnectionTag
* assigns a java.sql.Connection object to the
* "id" attribute at the end tag.
* @author Matt Shannon
* @see ConnectionTag
public class ConnectionTEI extends TagExtraInfo {
public final VariableInfo[] getVariableInfo(TagData data)
return new VariableInfo[]
new VariableInfo(
data.getAttributeString("id"),
"java.sql.Connection",
true,
VariableInfo.AT_END
data-sources.xml:
<?xml version="1.0"?>
<!DOCTYPE data-sources PUBLIC "Orion data-
sources" "http://xmlns.oracle.com/ias/dtds/data-sources.dtd">
<data-sources>
<data-source
class="oracle.jdbc.pool.OracleConnectionCacheImpl"
name="jdbc/pool/OracleCache"
location="jdbc/pool/OracleCache"
url="jdbc:oracle:thin:@oracle1:1521:pdev"
>
<property name="maxLimit" value="15" />
<property name="cacheScheme" value="2" />
<property name="user" value="console" />
<property name="password" value="console" />
<description>
This DataSource is using an Oracle-native DataSource Class so as
to allow Oracle Specific extensions.
A getConnection() call on this DataSource will return
oracle.jdbc.driver.OracleConnection.
The connection returned is a logical connection.
The caching scheme in place is Fixed Wait. Refer below to
possible values.
Dynamic 1
Fixed Wait 2
Fixed Return Null 3
</description>
</data-source>
</data-sources>
many thanks,
Matt.Hi. Show me your pool definition.
Joe
Ramamurthy wrote:
I am using the jsp custom tag library from BEA called sqltags.tld which came with Weblogic 5.1. Currently I am using Weblogic6.1 sp2 on Solaris.
I have created a Connection Pool for Sybase database using the driver com.sybase.jdbc.SybDriver.
When I created jsp page to connect to the connection pool using sqltags custom tag library, I am getting the error
"javax.servlet.jsp.JspException: Failed to write body content
at weblogic.taglib.sql.ConnectionTag.doAfterBody(ConnectionTag.java:43)
at jsp_servlet.__hubwcdata._jspService(__sampletest.java:1014)"
After this message, whenever I try to access the same jsp page I am getting the message
"javax.servlet.jsp.JspException: Failed to load JDBC driver: weblogic.jdbc.pool.D
river
at weblogic.taglib.sql.ConnectionTag.doStartTag(ConnectionTag.java:34)
at jsp_servlet.__hubwcdata._jspService(__sampletest.java:205)".
Can you please help me the reason why this problem is happening and how to fix this ?
This problem doexn't happen consistently. This occurs once in a while.
I tried to increase Login delay Seconds parameter in the Connection Pool to 15 sec. It didn't help me much.
Thanks for your help !!!
Ram -
Error in JSP Custom Tag Program
Hi Dear,
when I compile my JSP Custom tag program on weblogic Its give that Error..
Parsing of JSP File '/Home.jsp' failed: /Home.jsp(-1): cannot load TLD: weblogic.xml.dom.ChildCountException: missing child tagclass in tag
probably occurred due to an error in /Home.jsp line -1:
Tue Sep 09 18:46:56 GMT 2008
My Files are:
Home.jsp:
<%@ taglib uri="/WEB-INF/tlds/taglib.tld" prefix="neeraj" %>
<neeraj:hello name="Vijay">
It is a Tag Body<br>
</neeraj:hello>
taglib.tld:
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<uri>WEB-INF/tlds/taglib.tld</uri>
<tag>
<name>hello</name>
<tag-class>mypack.MyTag</tag-class>
<attribute>
<name>name</name>
<required>true</required>
</attribute>
</tag>
</taglib>
MyTag.java:
package mypack;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class MyTag extends TagSupport
String name;
public void setName(String c)
try
name=c;
catch(Exception e)
count=1;
public int doStartTag()
return EVAL_BODY_INCLUDE;
public int doAfterBody
JspWriter out=pageContext.getOut();
out.print("Good Night "+name);
catch(Exception e)
return EVAL_PAGE;
web.xml:
<web-app>
<welcome-file-list>
<welcome-file>/Home.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>taglib</taglib-uri>
<taglib-location>/WEB-INF/tlds/taglib.tld</taglib-location>
</taglib>
</web-app>
Please resolve my issue..I had the same problem. In your .tld change tagclass to tag-class and bodycontent to body-content and that should do the trick. The names slightly changed for JSP spec 1.2.
-
How to use JSP custom tag lib in PAR file?
Hi All,
I am trying to customize mastheaderpar file. For that I have downloaded relevant par file and making the changes accordingly.
As part of the changes I would require to use JSP custom tag library in my par file.
I have the TLD file and relevant classes in the jar file. I would like to know where and what kind of modifications have to be done to use the jsp custom tag library.
I tried modifying some things in portalapp.xml but was not successful.
Please help me on how to proceed with this? It would be great if you can provide the xml entry to use this tag library
Thanks
SanthoshHi Johny,
Thanks for the reply. Actually I am able to change colors etc. with out any problem.
My requirement is to use XMLTaglib in mastheader par file. This tag lib is from apache tomcat. I have the relevant TLD and class files. I copied TLD file into taglib dir of portal-inf and class file in src api.
And I have added the following line in portalapp.xml under component-profile section of default
<property name="tlxtag" value="/SERVICE/Newmastheader/taglib/taglibs-xtags.tld">
Is this the right way to use tag lib? Actually before adding this line I used to get the error saying "Error parsing taglib", but now the error does not occur and I am getting new error. This is an exception in one of the taglib classes.
Could any one provide me some inputs on how to check this error?
Thanks
Santhosh -
Data Streaming in JSP custom tag
We have a JSP custom tag which uses a StringBuffer object to store the HTML content. In the doEndTag method, we use the JSPWriter's print method to send the buffer's content to the browser.
Now, there are cases when the HTML content becomes very large,in the order of 1 - 10MB. In such cases, is there a way we can start streaming the data from the custom tag as the buffer is being built, rather than waiting for the entire buffer to be written out in the doEndTag.Yeah, just call the JSPWriter's print method instead of using the StringBuffer, or write your own subclass of StringBuffer (or StringBuilder if Java 5+) which will do this for you automatically when the size is at a certain point, and clear it out)
-
Can I write Design-time for JSP custom tag(not JSF components)
I have some old JSP custom tags(not JSF components), and I want to use them in the IDE through the toolbox.
Now I have already written the BeanInfos for these tags, and they can be drag from the toolbox; but it will throw a Exception when render the tags, and the properties in the Property Editor are not which I describe in the BeanInfos.
How can I write Design-time for these tags? or whether it is possible to write the Design-time for these tags?
the Exception is shown as follow:
java.lang.ClassCastException
at com.sun.rave.insync.faces.FacesPageUnit.renderNode(FacesPageUnit.java:1347)
[catch] at com.sun.rave.insync.faces.FacesPageUnit.renderBean(FacesPageUnit.java:1086)
at com.sun.rave.insync.faces.FacesPageUnit.getFacesRenderTree(FacesPageUnit.java:993)
at com.sun.rave.css2.FacesSupport.getFacesHtml(FacesSupport.java:152)
at com.sun.rave.css2.CssContainerBox.addNode(CssContainerBox.java:373)
at com.sun.rave.css2.CssContainerBox.createChildren(CssContainerBox.java:354)
at com.sun.rave.css2.DocumentBox.createChildren(DocumentBox.java:90)
at com.sun.rave.css2.DocumentBox.relayout(DocumentBox.java:160)
at com.sun.rave.css2.PageBox.layout(PageBox.java:392)
at com.sun.rave.css2.PageBox.relayout(PageBox.java:454)
at com.sun.rave.css2.DocumentBox.redoLayout(DocumentBox.java:313)
at com.sun.rave.css2.PageBox.redoLayout(PageBox.java:460)
at com.sun.rave.css2.DocumentBox.changed(DocumentBox.java:634)
at com.sun.rave.designer.DesignerPaneUI$UpdateHandler.changedUpdate(DesignerPaneUI.java:1012)
at com.sun.rave.text.Document.fireChangedUpdate(Document.java:851)
at com.sun.rave.text.Document$5.run(Document.java:631)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)I have some old JSP custom tags(not JSF components), and I want to use them in the IDE through the toolbox.
Now I have already written the BeanInfos for these tags, and they can be drag from the toolbox; but it will throw a Exception when render the tags, and the properties in the Property Editor are not which I describe in the BeanInfos.
How can I write Design-time for these tags? or whether it is possible to write the Design-time for these tags?
the Exception is shown as follow:
java.lang.ClassCastException
at com.sun.rave.insync.faces.FacesPageUnit.renderNode(FacesPageUnit.java:1347)
[catch] at com.sun.rave.insync.faces.FacesPageUnit.renderBean(FacesPageUnit.java:1086)
at com.sun.rave.insync.faces.FacesPageUnit.getFacesRenderTree(FacesPageUnit.java:993)
at com.sun.rave.css2.FacesSupport.getFacesHtml(FacesSupport.java:152)
at com.sun.rave.css2.CssContainerBox.addNode(CssContainerBox.java:373)
at com.sun.rave.css2.CssContainerBox.createChildren(CssContainerBox.java:354)
at com.sun.rave.css2.DocumentBox.createChildren(DocumentBox.java:90)
at com.sun.rave.css2.DocumentBox.relayout(DocumentBox.java:160)
at com.sun.rave.css2.PageBox.layout(PageBox.java:392)
at com.sun.rave.css2.PageBox.relayout(PageBox.java:454)
at com.sun.rave.css2.DocumentBox.redoLayout(DocumentBox.java:313)
at com.sun.rave.css2.PageBox.redoLayout(PageBox.java:460)
at com.sun.rave.css2.DocumentBox.changed(DocumentBox.java:634)
at com.sun.rave.designer.DesignerPaneUI$UpdateHandler.changedUpdate(DesignerPaneUI.java:1012)
at com.sun.rave.text.Document.fireChangedUpdate(Document.java:851)
at com.sun.rave.text.Document$5.run(Document.java:631)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100) -
Aggressive Caching of JSP Custom Tags?
I've just developed my first JSP Custom Tag. I compiled my class and it
worked fine. But subsequent changes to the class source and recompiles
don't affect the JSP output; evidently, these are aggressively cached, so
much so that 12 hours later it still won't change (I was hoping it would be
a 10 minute timeout or something like that.)
Is this the problem? If so, is there a weblogic.properties setting to tell
WL to check for modifications to the class file every so often?
David
Lets say i want to have some user defined exception messages.There
i will say in tag support or body tag support i will use JSPException
and throw my customised exception.
Can any one tell me any practical example.
If someone really have used it somewhere.
thanks
vijendra -
How to call a method repeatedly with JSP custom tag?
This senerio is very similar to the usage of StringBuffer.
I have a problem which can be solved easily with scriptlets:
<% NameValuePair nvp = new NameValuePair(request.getQueryString()); %>
<a href="foo.html?<%=nvp.add(name1", "value1").add("name2", "value2").toString();%">">Foo</a>
<a href="bar.html?<%=new NameValuePair(request.getQueryString()).add("x", 1).add("y", 2).toString()%>">Bar</a>
But I cannot use scriplets because it's turned off. I can only use jsp custom tag / jstl. How would I implement this functionality with a custom tag? How would the JSP code look like? Our container supports JSP 2.0.
Thanks.</a>hi,
you can do within 2 step-
1) use <%@page import="your_java_class"%>
2)use scriptlet code <%...%> and write coding in this tag.
means create instance of your java class .
<% your_java_class obj1=new your_java_class();
obj1.method_of_your_java_class();
%>or
3) you can make javabean to use method of java class.[Best option]
Thanx
Ranvijay -
Hello friends i am planning to learn jsp custom tags but i dont find any proper source or any material.....help me to find the proper URL to get the tutorials.
ThanksDid you look under tutorials on this site? The URL is http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags.html
-
JSP Custom tag not working correctly for multiple users
I am doing some support work for an existing web system. When doing single user access (a custom tag is called within the JSP); the output of the Custom tag is fine. However, during multiple user access to the JSP, as I could see on the log files, 2 users access the custom tag at exactly the same time- the output of one of the users was incorrect. The custom tag btw, uses TreeMap, Stringbuffer and does not have a body, only attributes passed to it. It takes an input file and a Hashmap as input attributes and it sets a string in the page context which is later being used in the JSP. No error is logged, its just that the string produced(placed in the page context) is incorrect. This only happens when this tag is called at same time(when multiple users accessing the page) Has anyone encountered this problem? Is there a known pooling/thread problem with custom tags?
in a servlet/jsp (a jsp is compiled into a servlet),
the class atrributes are shared. only the
variables declared in the doservice (doGet or doPost)
method are threadsafe.
post your jsp plzhere's the snippet of the jsp code:
<%@ page language="java"
errorPage="Error.jsp"
autoFlush="false"
buffer="128kb"
import="java.text.*,
java.math.BigDecimal,
java.rmi.RemoteException,
java.util.*,
java.io.*,
%>
<%@ include file="Secure.jsp" %>
// a set of request.getParameter are being called here
HashMap myMap = new HashMap();
myMap.put(xmlDPhoneNumber, dPhoneNumber);
myMap.put(xmlDPhoneType, "D");
myMap.put(xmlDPhoneExt, dExtension);
myMap.put(xmlDPhoneDigits, dPhoneDigits);
// other myMap putting of key values are called here
%>
<test:applyCustomerSearchValues id="resultXml" xmlTemplate="/xml/message/CustomerUpdateRequest.xml"
xmlMap="<%= myMap %>" />
<test:transformXMLString id="customerUpdateRequest"
xmlString="<%= resultXml.toString() %>"
xslFileName="/xsl/message/CustomerCreateRequest.xsl"
paramMap="<%= PMap %>"/>
now here's the thing: the xml produced by test:applyCustomerSearchValues is resultXml which is used in test:transformXMLString. I got no problem with the output of test:transformXMLString. I am sure that a phone number is being passed into the former as part of the HashMap key-value. However when test:applyCustomerSearchValues is called when 2 users access the jsp, it seems like the the first xml produced does not have the phone number in it - but the other has it. The xml is OK for both users, its just that the values of the HashMap do not seem to be passed correctly into the xml produced.
--- here's the snippet of the log, the first httpWorkerThread-80-6 does not have the phone number, however the second one-httpWorkerThread-80-7 has the phone number. The first one should also have a phone number as in the start of the log, the number was listed, but as the system called the test:applyCustomerSearchValues tag, the number was not included. There are different phone numbers for the 2 users. The odd thing here is, the userID which is the 'LastUpdatedBy' element has been set correctly. The userID is being fetched from a session attribute while the phone number is fetched from a request parameter, both are being placed in the HashMap attribute passed to the custom tag.
2007-06-05 10:55:41,954 DEBUG [httpWorkerThread-80-6] (?:?) - ApplyCustomerSearchValuesTag : String produced is :<Values><Customer>
<Status>
<CustomerType></CustomerType>
<FirstContactDate>2007-06-05</FirstContactDate>
<StatusFlags>
<Fraud>N</Fraud>
<BadCheck>N</BadCheck>
<BadCredit>N</BadCredit>
<DoNotMerge>N</DoNotMerge>
<ARHoldRefundCheck>N</ARHoldRefundCheck>
</StatusFlags>
<LastUpdatedDateTime>2007-06-05 10:55:41</LastUpdatedDateTime>
<LastUpdatedBy>5555</LastUpdatedBy>
<OPAlertClass></OPAlertClass>
<MailListStoreID></MailListStoreID>
<OriginatingSource>CSA</OriginatingSource>
</Status>
<DPhone id="D">
<DPhoneNumber></DPhoneNumber>
<DPhoneDigits></DPhoneDigits>
<DPhoneType></DPhoneType>
<DExtension></DExtension>
<DAreaCode></DAreaCode>
<DPhoneCountryCode></DPhoneCountryCode>
</DPhone>
</Customer>
</Values>
2007-06-05 10:55:41,954 DEBUG [httpWorkerThread-80-7] (?:?) - ApplyCustomerSearchValuesTag : String produced is :<Values><Customer>
<Status>
<CustomerType>N</CustomerType>
<FirstContactDate>2007-06-05</FirstContactDate>
<StatusFlags>
<Fraud>N</Fraud>
<BadCheck>N</BadCheck>
<BadCredit>N</BadCredit>
<DoNotMerge>N</DoNotMerge>
<ARHoldRefundCheck>N</ARHoldRefundCheck>
</StatusFlags>
<LastUpdatedDateTime>2007-06-05 10:55:41</LastUpdatedDateTime>
<LastUpdatedBy>1840</LastUpdatedBy>
<OPAlertClass></OPAlertClass>
<MailListStoreID></MailListStoreID>
<OriginatingSource>CSA</OriginatingSource>
</Status>
<DPhone id="D">
<DPhoneNumber>(123) 123-4788</DPhoneNumber>
<DPhoneDigits>1231234788</DPhoneDigits>
<DPhoneType>D</DPhoneType>
<DExtension></DExtension>
<DAreaCode>123</DAreaCode>
<DPhoneCountryCode>US</DPhoneCountryCode>
</DPhone>
</Customer>
</Values>
Message was edited by:
Mutya -
Database access with JSP custom tags
i have created one file in which i am making the connection with mysql data base with con.mysql.jdbc.Driver.and usking J connector and that i'm doing with custom tag.this is the error which i'm getting in tomcat.
and the tag handler class and TLD file and jsp file is below
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.servlet.jsp.JspException: null
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl .java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.j ava:778)
org.apache.jsp.DbTry_jsp._jspService(org.apache.jsp.DbTry_jsp:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException
Try.Connect.<init>(Connect.java:26)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.jasper.runtime.TagHandlerPool.get(TagHandlerPool.java:116)
org.apache.jsp.DbTry_jsp._jspx_meth_db_connect_0(org.apache.jsp.DbTry_jsp:84)
org.apache.jsp.DbTry_jsp._jspService(org.apache.jsp.DbTry_jsp:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.4 logs.
Apache Tomcat/5.5.4
Tag handler class
package Try;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import java.sql.*;
public class Connect extends TagSupport {
private String driver = "com.mysql.jdbc.Driver";
private String dbtype = "mysql";
private String host = "localhost";
private String username = "root";
private String password = "203131";
private String database = "compose";
private String scope = "page";
private String id = "";
JspWriter out = pageContext.getOut();
public void setDriver(String str) {
driver = str;
public void setDbtype(String str) {
dbtype = str;
public void setHost(String str) {
host = str;
public void setUsername(String str) {
username = str;
public void setPassword(String str) {
password = str;
public void setDatabase(String str) {
database = str;
public void setScope(String str) {
scope = str;
public void setId(String str) {
id = str;
public int doStartTag() throws JspException {
try {
Class.forName("com.mysql.jdbc.Driver");
String url= "jdbc:" + dbtype + "://" + host + "/" + database;
Connection connection = DriverManager.getConnection(url,username,password);
out.println("right ;;one");
catch (SQLException e1) {
System.out.println("Error in HeadingTagv: " + e1);
catch (Exception e) {
System.out.println("Error in HeadingTag: " + e);
return SKIP_BODY;
TLD is lib.tld
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>db</short-name>
<display-name>Database Tags</display-name>
<description>
A set of tags for working with SQL database access
</description>
<tag>
<name>connect</name>
<tag-class>Try.Connect</tag-class>
<body-content>empty</body-content>
<description>
</description>
<attribute>
<name>driver</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>
</description>
</attribute>
<attribute>
<name>dbtype</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>
</description>
</attribute>
<attribute>
<name>host</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>
Can be given by a run-time expression.
Host name of the computer where database is located.
Default is "localhost".
</description>
</attribute>
<attribute>
<name>username</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>
Can be given by a run-time expression.
Username for logging onto the database.
Default is "root".
</description>
</attribute>
<attribute>
<name>password</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>
Can be given by a run-time expression.
Password for logging onto the database.
Default is the empty string.
</description>
</attribute>
<attribute>
<name>database</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>
Can be given by a run-time expression.
The name of the database that will be used for
the SQL commands. Default is no database specified.
</description>
</attribute>
<attribute>
<name>id</name>
<required>false</required>
<description>
</description>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<description>
</description>
</attribute>
</tag>
</taglib>
JSP file is
<%@ taglib uri="/WEB-INF/lib.tld" prefix="db" %>
<html>
<body>
<db:connect username="root" password="203131" database="compose" />
</body>
</html>Answered in your other post:
http://forum.java.sun.com/thread.jspa?threadID=608780&tstart=0 -
JSP Custom Tag and Expressions for parameters
This should be an easy question. I am trying to use an expression for a
parameter to a jsp or custom jsp tag. When I hard code a value for the
parameter, the tag works fine but when I use the expression, the expression
gets evaluated but the tag itself does not resulting in the tag being shown
in my output.
For example:
<jsp:forward page="www.slashdot.org"/> works
<jsp:forward page="<%=request.getParameter("DESTINATION")%>"/>
places the following into my html output
<jsp:forward page="www.slashdot.org"/>
Can someone please tell me what I am doing wrong or at least offer some
debugging hints?
Thanks in advance!
Jacob Meushaw
I have experienced almost this exact same problem, but with a custom
tag. And I did make sure that my attribute specified
<rtexprvalue>true</rtexprvalue>. Here is the weird part.
If I do the following JSP code everything works fine:
<% String foo = request.getParameter("bar"); %>
<mytag:custom param="<%= foo %>"/>
But if I do this:
<mytag:custom param="<%= request.getParameter("bar") %>"/>
I get the following in my html output:
<mytag:custom param="whatever bar is set to in the request"/>
It appears that the JSP container only does a one pass evaluation.
Is this the spec of is this a bug?
Jacob Meushaw wrote:
>
> This should be an easy question. I am trying to use an expression for a
> parameter to a jsp or custom jsp tag. When I hard code a value for the
> parameter, the tag works fine but when I use the expression, the expression
> gets evaluated but the tag itself does not resulting in the tag being shown
> in my output.
>
> For example:
>
> <jsp:forward page="www.slashdot.org"/> works
>
> <jsp:forward page="<%=request.getParameter("DESTINATION")%>"/>
> places the following into my html output
> <jsp:forward page="www.slashdot.org"/>
>
> Can someone please tell me what I am doing wrong or at least offer some
> debugging hints?
>
> Thanks in advance!
>
> --
> Jacob Meushaw
Jeff Smith
[email protected]
BEA Systems, Inc.
720-565-6613
-
Initial problem with JSP Custom Tag devolopment
Hi ,
I have encountered a problem with my JSP application which utilizes a simple custom tag.
First I created followinng directories.
1. %TOMCAT_HOME%\webapps\testTags
2. %TOMCAT_HOME%\webapps\testTags\META-INF
3. %TOMCAT_HOME%\webapps\testTags\WEB-INF
4. %TOMCAT_HOME%\webapps\testTags\WEB-INF\tlds
5. %TOMCAT_HOME%\webapps\testTags\WEB-INF\classes
6. %TOMCAT_HOME%\webapps\testTags\WEB-INF\classes\com
7. %TOMCAT_HOME%\webapps\testTags\WEB-INF\classes\com\tek271
8. %TOMCAT_HOME%\webapps\testTags\WEB-INF\classes\com\tek271\testTags
I created the essential four files, that is named as follows.
1.TagError.java
2.web.xml
3.testTld.tld
4.testJsp.jsp
Then i put the files under these directories as given below
testJsp.jsp under %TOMCAT_HOME%\webapps\testTags.
web.xml under %TOMCAT_HOME%\webapps\testTags\WEB-INF
TagError.java under %TOMCAT_HOME%\webapps\testTags\WEB-INF\classes
TagError.class under %TOMCAT_HOME%\webapps\testTags\WEB-INF\classes\com\tek271\testTags
testTld.tld %TOMCAT_HOME%\webapps\testTags\WEB-INF\tlds
Here is the content inside the files.
1.TagError.java
package com.tek271.testTags;
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class TagError extends TagSupport {
private String mColor = "red";
public void setColor(String aColor) {
mColor = aColor;
} // setColor
public int doStartTag() throws JspException {
try {
JspWriter out = pageContext.getOut();
out.print("<font color=\"");
out.print(mColor);
out.print("\"><b>Error: ");
} catch (IOException ex) {
throw new JspTagException(ex.getMessage());
return EVAL_BODY_INCLUDE; // other return: SKIP_BODY
} // doStartTag()
public int doEndTag() throws JspException {
try {
JspWriter out = pageContext.getOut();
out.println("</b></font><br>");
} catch (IOException ex) {
throw new JspTagException(ex.getMessage());
return EVAL_PAGE; // other return: SKIP_PAGE
} // doEndTag()
} // TagError
2.web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<taglib>
<taglib-uri>/testTaglib</taglib-uri>
<taglib-location>/WEB-INF/tlds/testTld.tld</taglib-location>
</taglib>
</web-app>
3.testTld.tld
<?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>testTld</shortname>
<info>Testing jsp tags</info>
<tag>
<name>tagError</name>
<tagclass>com.tek271.testTags.TagError</tagclass>
<bodycontent>JSP</bodycontent> <!-- Also: empty, tagdependent -->
<info>Show a string as an error message</info>
<attribute>
<name>color</name>
<required>false</required>
</attribute>
</tag>
</taglib>
4.testJsp.jsp
<%@ taglib uri="/testTaglib" prefix="test" %>
<html>
<head>
<title>Testing Tag Library</title>
</head>
<body>
<test:tagError>Invalid user name</test:tagError>
<test:tagError color="blue">Invalid Password</test:tagError>
</body>
</html>
but i am getting the following error.
Apache Tomcat/4.0.3 - HTTP Status 500 - Internal Server Error
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: File "/testTaglib" not found
at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:214)
at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:174)
at org.apache.jasper.compiler.JspParseEventListener.processTaglibDirective(JspParseEventListener.java:1162)
at org.apache.jasper.compiler.JspParseEventListener.handleDirective(JspParseEventListener.java:758)
at org.apache.jasper.compiler.DelegatingListener.handleDirective(DelegatingListener.java:121)
at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:255)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1145)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1103)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1099)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:213)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:210)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:552)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:189)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:536)
why is it like this ?please give me a solution.
Thanking in advance.
From
Vinod A.Dear patreck ,
It does not work.
I have replaced the line
<%@ taglib uri="/testTaglib" prefix="test" %>
with
<%@ taglib uri="WEB-INF/tlds/testTaglib" prefix="test" %>
but now it shows the error ,
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: File "/testTags/WEB-INF/tlds/testTaglib" not found
any more suggestion ?
From Vinod A. -
Jsp/custom tag compiler error (HttpServletResponse)
I originally posted with on Oracle's site but I am not getting any help.
Our server is running Oracle 9ias with JServ and Apache.
I have created a simple jsp that calls a custom tag but I am getting the following error:
Method addHeader(java.lang.String, java.lang.String) not found in interface javax.servlet.http.HttpServletResponse.
response.addHeader("Pragma", "No-cache");
^
Is something not setup correctly or installed where it should be?
the code for the custom tag is from the O'reilly book "JavaServer Pages." This works with JDeveloper on my computer but not on our server.
package info.wyoroad.jsp.tags.generic;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
* This class is a custom action for setting response headers
* that prevent the page from being cached by a browser or
* proxy server.
* @author Hans Bergsten, Gefion software <[email protected]>
* @version 1.0
public class NoCacheTag extends TagSupport {
* Sets "no cache" response headers
public int doEndTag() throws JspException {
HttpServletResponse response =
(HttpServletResponse) pageContext.getResponse();
response.addHeader("Pragma", "No-cache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 1);
return EVAL_PAGE;
}The jsp looks like:
<%@ page language="java" contentType="text/html;charset=WINDOWS-1252"%>
<%@ taglib uri="/WEB-INF/wylib.tld" prefix="info" %>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=WINDOWS-1252">
<META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
<info:NoCache />
<TITLE>
Test tag
</TITLE>
</HEAD>
<BODY>
<H2>Test the tag NoCache</h2> </P>
</BODY>
</HTML> -
Initialization of parameter values in JSP Custom Tag Handlers
Hi - I have a tag handler for a custom tag that has no body, but accepts
some parameters.
If the parameters are optional and are passed with the tag in the source jsp
page, then all is fine.
However, for subsequent uses of the same tag in the same page if the
optional parameters are omitted, the previous values remain in the instance
of the tag handler class, as the attributes for the tag handler are declared
as instance variables (with corresponding getters and setters) as per the
tag handler specs.
eg:
<abc:sometag attrib1="a" attrib2="b"/>
if attrib1 and attrib2 are optional, then a subsequent use of this tag, eg:
<abc:sometag/>
attrib1 and attrib2 still have their previously assigned values of "a" and
"b".
Is there a method I can call to get the actual values of the attributes that
were passed on a particular call to the tag handler, or is there a way to
initialize the attributes before the tag handler processing method, eg
doBeforeBody(), doAfterBody(), is called?
Thanks,
Kevin Hooke
Yeah, just call the JSPWriter's print method instead of using the StringBuffer, or write your own subclass of StringBuffer (or StringBuilder if Java 5+) which will do this for you automatically when the size is at a certain point, and clear it out)
Maybe you are looking for
-
Setup google calendar in calendar
We have 2 step verification setup on my wife's macbook. Is there some special we need to do in Calendar to get it to sync with google calendar?
-
I just updated to Mavericks and now my iPhoto won't open
I just updated my imac to mavericks, now my iphoto wont open. how do I fix this
-
hi, I dont have separate G/L account for deductable and non deductable input tax for vat so in JVRN should account be hit while doing MIRO or not? and In NVV condition in OB40 should a G/L account must be spacified or not ? In MIRO from where does th
-
Hi all, This is probably nothing technical at all but it's something that really bugs me! The album artwork on the cover shows the same album two to three times, is this strange and is there anything i can do to get rid of it. it really annoys me!!!
-
Livedrive ir bay [problems with internal drive bay - help plea
i am also having issues with my li'vedri've ir bay, the line2 and mic2 ports are both seen on the volume mixer but they dont seem to work... i have only just recieved the sound card and dri've bay from a friend and as such i dont have the driver cd.