• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java/JSP question

Atheus

Diamond Member
OK - in one jsp page a bean is created like so:

<jsp:useBean id="xmlPage" scope="session" class="box.cms.xmlPage"/>

Some variables are set on it, it is initialized, it works, all is good.

Then I make an AJAX request from the generated page to another jsp page on the server like so:

req.onreadystatechange = callback;
req.open('GET',url,true);
req.setRequestHeader("Content-type", "text/xml");
req.setRequestHeader("Content-length", content.length);
req.setRequestHeader("Connection", "close");
req.send(content);

The new jsp page tries to access the bean:

isLocked = xmlPage.isPageLocked(userID);

"There has been a problem with the request."

Why?

BTW I know nothing about Java beans and most of this isn't even my code. I'm cleaning up someone else's mess here...

Thanks.
 
Ahhhhhhhh ... Beans .... Nooooooooo

Man, I hate web dev. Thank god I'm getting paid to do stand alone apps in Java.

I might learn web page BS in the fuiture, simply because it is the future. (PUKES)
 
It's been a while since I've done stuff like this but I believe that you have to put the <jsp:useBean .../> in the second page as well or the name xmlPage will not be in the local namespace. The bean should get created the first time the tag is encountered in that session and any subsequent times it will simply retrieve the bean from the session scope.

I'd also like to add that this is a very poor way of implementing business logic. Jsps should be for laying out html (or xml) only and the rest should be via servlets. Even then, they're kinda weird. (I don't know that you're not using servlets, but the xmlPage.isPageLocked(userID) suggests business logic to me.)
 
kamper: Thanks for your reply, yes the useBean lines are in the second page as well.

I've narrowed things down a little.

There is another bean used in the same way. 'loginBean' created in page.jsp...

<jsp:useBean id="loginBean" scope="session" class="box.login.Login"/>

Although this one appears to work fine in the second page. Relevant code:

<jsp:useBean id="xmlPage" scope="session" class="box.cms.xmlPage"/>
<jsp:useBean id="loginBean" scope="session" class="box.login.Login"/>
<%
int userID = loginBean.getUserID();
boolean isLocked = xmlPage.isPageLocked(userID);
...

The userID is fetched fine, but the 'isPageLocked' line gives a null pointer error on this line of xmlPage.java:

if(sql.select(statement.toString()))

So it seems as if the variable 'sql' has not been initialized. I thought at first that the session was not being recognized, and so the useBean line is creating a new instance of xmlPage rather than using the one created in page.jsp, but if that is the case, why am I able to get the userID from loginBean? Surely both session beans should behave in the same way... is there something special I need to know about AJAX and sessions?...

I totally and completely do not get it. If anyone can help it would be much appreciated, if I don't get thins done by the weekend I am going to be in very hot water.


 
Print out what the variables sql and statement are right before that line in the bean.

Looks like the beans are being used properly, but there might be a problem within xmlPage.java itself.
 
Do you know you're getting the right session id (not 0 or something default)?

I don't know about ajax and sessions but the first thing I thought was that maybe the same cookies aren't passed back as a regular request. But that doesn't really make sense because it would make it almost useless (or extremely insecure...).

At this point, it's really hard to make suggestions from here without seeing more code (like the complete code for both beans and both jsps). Don't know if you can do that or not... Also, do you have an evironment set up in which you can debug the live thing? Doing the jsp might be hard, but at least catching it in the bean code would be useful. Or if you have some sort of decent logging framework to fake debug it would be almost as useful.
 
Back
Top