• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsp page is not displaying anything

 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doers View Source show any HTMl at all?

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

 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Arundhathi and Bear.
 
shanthi naidu
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic