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
posted
0
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().
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
posted
0
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 .
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
posted
0
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
forward(ServletRequest request, ServletResponse response)
Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.