In what ways can you pull something from the request?

How can I get that value out of the request within a JSP? I believe I can do either of these:

but I'm having difficulty getting the second one to work. I know that you can set your app server to ignore EL, but I haven't done so. Yet, the result is that the first line reads "Corey" and the second line reads "${user}". Obviously, the EL expression is not being interpreted. Anyone know why that might be?

Additionally, are there any other ways I might get that value from the attribute, besides using an expression or an EL expression?

The access of ${user} should work. You may want to check into your Containter (tomcat / jboss) config.

I was successfully able to use something similiar in Tomcat 5.0.28 without any problem.

You can access objects by <jsp:useBean id="user" type="com.example.User" />

The id parameter identifies the name of the object. The type identifies the class or interface.. NOTE the object must exist. There is a class parameter - which will create the object if it does not exist... (this can NOT be an abstract class because if it does not exist it will need to be instatiated) There is also a scope parameter to identify the scope of the 'bean'.

Well, Kathy, you're right, I don't have the most recent info, but that doesn't quite solve my problem, either.

Here's what I currently have for a web.xml file (entirely generated by WSAD):

If I try to add in the snippet you gave me, so I end up with this:

Then I end up with 21 errors. The errors seem to all of this nature:

Of course, I checked out the DTD file referenced from the second line:

As I expected, those attributes are not defined within that DTD. Hence, all the errors. Well, the lines you provided me with, Kathy, include an xml schema so I didn't really see the need for the DTD line, anyway, so I tried removing it, to end up with a web.xml file that looked like this:

What happens if you make the web-app tag *exactly* like the one I pasted in? Can you take out the id="WebApp"? Someone here must know WSAD... did you try the regular Servlets and JSP forums?

Wish I had more helpful info

Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271

posted Oct 22, 2004 15:49:00

0

Originally posted by Kathy Sierra: What happens if you make the web-app tag *exactly* like the one I pasted in? Can you take out the id="WebApp"? Someone here must know WSAD... did you try the regular Servlets and JSP forums?

Wish I had more helpful info

Yeah, I tried that, still no luck. Without the DTD line, it's like WSAD doesn't understand what the XML doc should be and it doesn't seem to pay any attention to the xmlSchema information.

I haven't trued the other forums because, originally, I thought this was just a problem with the way I was writing my EL. It would appear now, however, that it's a problem with me DD.

Nope, all you need is ${user}, although if you think there may be more than one "user" attribute in the four possible attribute scopes (page, request, session, and application), you can prefix with the scope using the implicit object that represents a MAP of the scope attributes.

But it's "requestScope" not "request".

So, assume there is only one attribute named "user", then

${requestScope.user} and ${user} have the same result

You can also use the implicit scope map when you have an attribute name that doesn't follow normal Java identifier rules.

An example we use in the book is: What if you have an attribute named "foo.person"? Imagine you did request.setAttribute("foo.person", p);

You would be in trouble, because you could not use:

${foo.person.name}, because the dot between person and name is perceived to be the dot OPERATOR.

But if you use the requestScope implicit object, then you can use quotes like this:

${requestScope["foo.person"].name}

So using the scope lets you put the attribute name in quotes, which you can't do if you simply want to name the attribute.

cheers, Kathy

Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271

posted Oct 22, 2004 19:01:00

0

Originally posted by Nicholas Cheung: An additional question to Corey's.

Should we use ${request.user}, instead of ${user}?

If not, what's the difference?

Nick

Actually, I don't think ${request.user} will compile. There is no implicit object called "request". Rather, I believe you have to do this: ${requestScope.user}. (But I haven't compiled this on my own to know for sure.)

If you don't use a scope, you'll end up searching all scopes, starting at page scope. If no matching attribute is found there, you'll go on to search request scope, followed by session scope and application scope. If no attribute is found in any scope, a new attribute is created in page scope.

If you include a scope, such as requestScope, only that scope will be searched and, if no matching attribute is found, a new attribute will be made at request scope.

Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

posted Oct 22, 2004 19:03:00

0

Oh... sorry for the typo.

If a scope is not given, all scopes would be searched. However, how about if there are 2 scopes that contain the same key?