JSP Problem with printing return arguments

Hi there, I'm starting to work with jsp, and I don't have exp with it. The problem is that I've tried a simple test, just a test.class that has a function that returns a String. And I'm trying to print on the screen but it simply don't print.

Here is the code:

<%@page import="java.util.*" %>

<%@ page import="TestesCamara.obterLideresBancada" language="java" %>

<jsp:useBean id="test" class="TestPackage.testClass" scope="session"/>

<table width="650" border="0" cellpadding="5" cellspacing="5">

<tr><td colspan="5" class="BodyCopy">

Result: <%test.testFunction();%>

</td></tr>

<tr><td>

</TR>

</table>

</body>

</html>

I know it's a simple question, but it's really freaking me out, please, some help is need here. And sorry about my poor english.

Thanks.

[949 byte] By [jmadrida] at [2007-11-26 13:16:13]
# 1
NullPointerException? Do you get a blank screen or something else? And why didn't you ask in the JSP forum?
CeciNEstPasUnProgrammeura at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 2
Oh, sorry, I saw some jsp issues here and didn't think twice.I get a page with.Result:Only.
jmadrida at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 3
And what's the bean's code?
CeciNEstPasUnProgrammeura at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 4
public class testClass {public String testFunction() { return "Uhuuuu";} }
jmadrida at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 5
Correction:<%@ page import="TestPackage.testClass" language="java" %>I've pasted wrond. Sorry
jmadrida at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 6
And so there actually is a bean instance provided?
CeciNEstPasUnProgrammeura at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 7
Sorry the ignorance, but how can I test or just know if the bean instance is being provided?I'm using netbeans to build everything.
jmadrida at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 8

> Sorry the ignorance, but how can I test or just know

> if the bean instance is being provided?

You could check the reference for null. I don't know, ask the JSP folks.

I only see that you say "take this bean instance and print its value", but don't seem to bother to actually provide a bean instance tht could be used.

CeciNEstPasUnProgrammeura at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 9
Ok thanks, i've already posted on the jsp forum.But this line isn't providing the bean?<jsp:useBean id="test" class="TestPackage.testClass" scope="session"/>?
jmadrida at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 10

> <jsp:useBean id="test" class="TestPackage.testClass"

> scope="session"/>?

That's just an import and some JSP instruction, I think it includes a loop and saying that the beans with that name should be picked from the session. How would the JSP know what you want to print?

CeciNEstPasUnProgrammeura at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 11
you get an NPE because the bean is not in session scope. you have no code to put it there, so it's not available to you.%
duffymoa at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 12
Thanks a lot man, it was that.in the line:Result: <%test.testFunction();%>It was missing to say jsp print.... and the correct way is this one:Result: <%= test.testFunction() %>Thanks.
jmadrida at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...
# 13
O_o
CeciNEstPasUnProgrammeura at 2007-7-7 17:37:54 > top of Java-index,Java Essentials,Java Programming...