This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Java Simple Tag Handler

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark :)
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic