Solved

can't figure out namingException

Posted on 2007-11-27
4
1,095 Views
Last Modified: 2008-02-01
I get the error shown below. It is repeated twice more for lines 27 and 28. I use these exact same three lines of code in various other places in my jsp pages. The only difference is these particular lines are include in a subroutine (<%! ... %>) whereas the others are in-line in the jsp page. What is my problem??!! I'm so confused!

An error occurred at line: 26 in the jsp file: /include/email.inc
Unhandled exception type NamingException
23:    
24:     if ((from == null) || (from.length() == 0))
25:     {
26:           Context ctx = new javax.naming.InitialContext();
27:           Context env = (Context) ctx.lookup("java:comp/env");
28:       replyAddr = (String) env.lookup("webUser");
29:       

0
Comment
Question by:jmarkfoley
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 20362337
you need to put it ina  try/catch block

try
{
           Context ctx = new javax.naming.InitialContext();
           Context env = (Context) ctx.lookup("java:comp/env");
       replyAddr = (String) env.lookup("webUser");
}
catch (NamingException ex)
{
   // handle exception
}
0
 
LVL 5

Expert Comment

by:deeppra
ID: 20363093
Your are getting the same error message when u place these lines inline jsp
0
 
LVL 1

Author Comment

by:jmarkfoley
ID: 20363759
So, explain why I need a try/catch block in a subroutine, but not in the "main" program? Is there an implied try/catch on the main page?
0
 
LVL 92

Expert Comment

by:objects
ID: 20363873
>  Is there an implied try/catch on the main page?

yes. though its not really implied. the generated method is defined to handle the exception.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now