File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Simple Tag Handler

 
Mohit Chauhan
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , My code is as below ....
with following jsp's,classes and tld files :

Getting exception for its execution:



form.jsp:






web.xml:





SimpleServlet.java : [Servlet class]










SimpleTagDynamic.java : [TagHandler Class]









simple.tld:










I am getting here exception as :

type Exception report

message An exception occurred processing JSP page /form.jsp at line 7

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

exception:

org.apache.jasper.JasperException: An exception occurred processing JSP page /form.jsp at line 7

4: <form method="POST" action="Dynamic.do">
5: <p>Select beer characteristics
6: Color:
7: <formTags:select name='Color' size='1' optionsList='${applicationScope.colorList}' />
8: <br>
9: </form>
10: </body>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.lang.NullPointerException
foo.SimpleTagDynamic.doTag(SimpleTagDynamic.java:60)
org.apache.jsp.form_jsp._jspx_meth_formTags_005fselect_005f0(form_jsp.java:107)
org.apache.jsp.form_jsp._jspService(form_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)




Please help ...
 
Marc Pfaller
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope it's not too late to help you.

In your SimpleTagDynamic Class you construct your html select Tag.

1. In Line 48 you open the select Tag, but it is never closed. You should close it with /> or </select>
2. In Line 48 there has to be a whitespace after the <select otherwise the html code would look like <selectname='myAttributesName'

Before: out.println("<select");
After: out.println("<select ");

And in Line 68 there has to be a whitespace too after the second %s otherwise your html code will stick together like in the example above.

Before: private static final String ATTR_TEMPLATE= "%s='%s'";
After: private static final String ATTR_TEMPLATE= "%s='%s' ";

In your SimpleServlet you fill your colorList and set it as an Context Attribute, but the Servlet is never invoked (Your html form has the action Dynamic.do), therefore the attribute is never set and when you try to get the optionsList in the SimpleTagDynamicClass you will get the NullPointerException.

Good Luck :)
 
Mohit Chauhan
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic