File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Jsp page is not displaying anything Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp page is not displaying anything" Watch "Jsp page is not displaying anything" New topic
Author

Jsp page is not displaying anything

Pawan Arora
Ranch Hand

Joined: Sep 14, 2008
Posts: 105
Hi,

I've created simple jsp page, in which it is calling a method of 'Person' attribute object, but it is not displaying anything in the output. First the request goes to servlet class, and then it is intializing a Person class, and then creating a attribute with the name 'Person', and then dispatching it to the Jsp page(result.jsp) in request scope.

The servlet class and Model class is in src folder.

Here's the servlet code:


Here's model class code:



and here's jsp code:



what's wrong I'm doing? I'm not getting any output?

Thanks in advance.
Arundhathi Menon
Ranch Hand

Joined: Jan 14, 2004
Posts: 113
Hi,

You need to import the class Person in your jsp :

<%@ page import ...... %>

Am guessing this could be the reason it doent understand person.getName().

Try this.


SCJP , SCWCD , SCBCD , SCDJWS
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Doers View Source show any HTMl at all?

usually "no output" means an exception has occurred on the server. Check the logs.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pawan Arora
Ranch Hand

Joined: Sep 14, 2008
Posts: 105
Thanks Arundhathi and Bear.
shanthi naidu
Ranch Hand

Joined: Nov 13, 2008
Posts: 39
Hi pawan arora,

It would be better if you place in a package and then import it in your jsp.

Your getName() returns a string... declare a string variable and call the function.
Display that string in expression tags(<%= stringhere %> ...

isha krishnan
Ranch Hand

Joined: Nov 10, 2008
Posts: 50
i am also doing bit same thing and am getting nullpointer exception on JSP page.
The servlet code is


the .jsp file is

here it extracts the "name" value.
i have imported servlet into .JSP also usein <%@ page import=""%>

Why value is not persisting in the request?

Thanks......
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you trying to include the contents of the JSP on the same page? Inside a loop? Try using "include" instead of "forward".

This isn't production code, is it??
isha krishnan
Ranch Hand

Joined: Nov 10, 2008
Posts: 50
i am trying to receive result set returned from servlet. I want to display the result set in form of a table on the JSP page.So result set is required to be accessd by jsp.
<jsp: include page =..> is to include some page . i dont want that.Its like every time i change the selection in a query , every time result set is different. So have to display that dynamic data on the same page from where request goes without reloading the whole page again and again. i am using ajax to implement it. But i am not able to disply dynamic data .
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh; I misunderstood-I thought both snippets were from a JSP page. (That aside, include() *is* a RequestDispatcher method.)

How many matching rows are there for the query? Do they all have a name? I don't know if you can forward multiple times like that, but maybe you can--I've just never done it (or had a need to). If that's legal, then something else is amiss, as you're setting the attribute correctly.

Personally, I'd consider doing it a different way--by creating a list of names in session and doing the looping in the JSP.
Arundhathi Menon
Ranch Hand

Joined: Jan 14, 2004
Posts: 113
Hi,

1) In your JSP , you need not import the Servlet if all you are doing is
<% = request.getAttribute("name").toString()%>
Had you been doing <% ... person.getName()%> , basically been using a Java class method , you wld have had to import that Java class whose getter method you are using

2) RequestDispatcher -
Try this -

RequestDispatcher dispatcher = request.getRequestDispatcher(.........);
dispatcher.forward(request,response)

forward(ServletRequest request, ServletResponse response)
Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jsp page is not displaying anything