• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting the Servlet Context In Jsp  RSS feed

 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All;

I have the following line in my JSP:

It returns a null where it should return the value of the siteName param from the web.xml.

Why doesn't this work? I looked at the java code compiled from the JSP:

This looks like it should work.

Any ideas?

Thanks,

Luke
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just looking at the generated code for the servlet and noticed a reference to the context is already being created:



This occurs in the jsp service method.

So I changed my JSP to:



But still null value returned. What am I doing wrong?

Luke
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the siteName param defined in the web.xml?
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


It is not with in a servlet definition.

Luke
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awww. There is my problem. <content-param>?? What was I thinking?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luke,

Another tip:

JSP provides a set of implicit object variables for you.
One of them is the 'application' variable.

getServletContext().get....

can be replaced with:

application.get....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!