permaculture playing cards*
The moose likes Servlets and the fly likes JSP not picking up getAttribute from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP not picking up getAttribute from Servlet" Watch "JSP not picking up getAttribute from Servlet" New topic
Author

JSP not picking up getAttribute from Servlet

Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hello All,

I've been posting my problems here and I am glad it was answered.

I have another assignment. I am halway there, but the last bit is not working.

I have a servlet file which the code looks like this:



When I query, the result came out successfully in the command prompt (where the tomcat server started up and displayed) but in the viewSearch.jsp, there is no result displayed.

My viewSearch.jsp looks like this:



What's wrong? Is it because of my configuration of web.xml or these codes?

Thanks in advance for helping me.
karthick Soundararaj
Greenhorn

Joined: Mar 09, 2009
Posts: 26
check the log file to see if some exception has occured


A java addict
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

i dont know what is your requirement to display. i dont see any logic (setting values into List and Iterating it in jsp) in your code. Personally i recommend to use TO(Transfer Object)
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Your code look fine.

What exactly happens when you hit the link to reach the 'Search' class. I mean do you get the viewSearch.jsp page displayed in the browser with the message No Record or do you end up seeing a blank page or some thing else?


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684


Hi,

we didn't get what's your code logic.

you are trying to add al ArrayList just because color your line.

But i think that will done your only with ArrayList emp_list just iterate your list with status and according to odd or even put your color.

No need to do this complex logic.



Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hello All,

thanks for replying. Maybe I didn't clearly explain my program. I have three files:
1)search.jsp (to enter search criteria),
2)search.java, (to connect to DB and query the DB) and
3)viewSearch.jsp (to display the search result).

When I enter a search criteria at search.jsp, it goes to search.java to find the
record in the database. I can see the search result in the command prompt
but in the viewSearch.jsp, stated "No Record Found" (I can see the table and all).

I can explain more if this is not enough. Really need some lights shed here.

Thanks in advance.

Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hi Karthick,
I see the logfile and no exception occured.

Hi Nishan,
I don't really understand what are your explanation. Please share with me your ideas
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684



Hi Emma Aziz,

What i mean first of all you are using scriplet into your jsp page....which is not good for coding....

So, i mean use JSTL <c:forEach tag which gives you iterate your list so no need to write java code and iterate.

That JSTL tag provide you status attribute which gives you odd and even row status what you want. But you use it using division operation and find it is odd or even that gives JSTL. just put your color according to status attribute.

That's what i mean.







>
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Emma Aziz - For all the design suggestions that you have got - your code is still correct the way it is. You could try putting a few System.out.println() statements in your JSP to find out how the flow is happening - that would give you some idea of whats going wrong...

Yes I agree with everyone out here that there are lot of design improvements that could be made to the code - it still does not answer the question why the current code is not working? Any thought on that?
Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

i tried this :


and got no messages on server console !!
i think the scriplets aren't working ... m looking into why


Anrd
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Aniruddh Joshi wrote:i tried this :


and got no messages on server console !!
i think the scriplets aren't working ... m looking into why


Your code is incorrect. Its going to throw a class cast exception at line 33 --> ArrayList empList = (ArrayList) itr.next();
That because the itr.next() is going to return the String 'Aniruddh' which is the first element in the ArrayList.

The problem with the original code is on similar lines. Here is the code that works..



Frankly - the code does need a lot of redesign - would have loved to help more but running short of time right now ...
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Yes,
I noticed that too. The scriptlets are not working. Anything under the tag <% %> are not working.

Anyone here knows how to solve this? Am really helpless here.

Thanks in advance
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Yes,
I noticed that too. The scriptlets are not working. Anything under the tag <% %> are not working.

Anyone here knows how to solve this? Am really helpless here.

Thanks in advance
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Yes,
I noticed that too. The scriptlets are not working. Anything under the tag <% %> are not working.

Anyone here knows how to solve this? Am really helpless here.

Thanks in advance
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Yes,
I noticed that too. The scriptlets are not working. Anything under the tag <% %> are not working.

Anyone here knows how to solve this? Am really helpless here.

Thanks in advance
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Yes,
I noticed that too. The scriptlets are not working. Anything under the tag <% %> are not working.

Anyone here knows how to solve this? Am really helpless here.

Thanks in advance
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
As I see, you are using a List of Lists wherein you store employee information(like first name, last name etc) in a list and then add this list to another list which contains other such list of employee details.
And then in the JSP, you iterate over the main list and get its inner lists, each list containing employee details. The logic seems to be fine. Try putting log statements at various steps, or use a debugger and step through the code to figure out, what's going wrong.


Thanks and Regards
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Emma Aziz wrote:Yes,
I noticed that too. The scriptlets are not working. Anything under the tag <% %> are not working.


then you need to tell us in begining itself right? you are wasted everybody time here
Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

this works :



but m not clear about you alternate color scheme.. and of course this code could be written in a better way
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
@Aniruddh Joshi
I agree your code works but I think the original code is slightly different and uses list of lists and you are using only a single list for 1 employee.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684


Hi,

Just check your web.xml if you find any thing like


just remove ...

Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

@ Satya
I know it satya,
I have just rectified the mistake and left the further implentation for her
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Emma,

Did you solve this problem ? still scriptlets not working ?
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hi Seetha,
I have just figured it out before Anirudh pointed it out

Hi Anirudh,
I've tried your codes and it is still, not working.

Hi Nishan,
There is no entry of that kind in my web.xml.

Hi Balu,
Yes, I have solved the problem. I removed and added again the Classpath in the Environment Variable, stop start service, and the problem, was solved.

I've tried putting some texts under the scriplets but anything didn't come out.

Thanks in advance.

Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hi Seetha,
I have just figured it out before Anirudh pointed it out

Hi Anirudh,
I've tried your codes and it is still, not working.

Hi Nishan,
There is no entry of that kind in my web.xml.

Hi Balu,
Yes, I have solved the problem. I removed and added again the Classpath in the Environment Variable, stop start service, and the problem, was solved.

I've tried putting some texts under the scriplets but anything didn't come out.

Thanks in advance.

Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hello,
Does anyone knows what is the solution? I've tried so many ways, the output are still the same.

Thanks.
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hello All!

I am excited. I solved the problem. It is, surely, my web.xml configuration. Any scriplets under this application folder won't work, then I tried putting the jsp with a really simple scriptlets, is also not working. When I put them under other application folder, it worked.

So, I tried taking the other's web.xml, paste it under my application folder, and yes, the result is displayed.

I thanked all of you for helping me out of the block.

Thanks.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Emma Aziz wrote:Hello All!

I am excited. I solved the problem. It is, surely, my web.xml configuration. Any scriplets under this application folder won't work, then I tried putting the jsp with a really simple scriptlets, is also not working. When I put them under other application folder, it worked.

So, I tried taking the other's web.xml, paste it under my application folder, and yes, the result is displayed.

I thanked all of you for helping me out of the block.

Thanks.


Hi Emma,

Did you really realize what is what is not working? Just copy pasting other xml can work but is better if you compare both to see what was going when it was not working, so the next time you will not lose time ;)
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hello Albareto,

I will try to do that next time.

Thank you very much for the advice

Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

you can even paste it now
Emma Aziz
Greenhorn

Joined: Apr 27, 2009
Posts: 23
Hello,

The web.xml which was not working is:



and the working one is:



I missed out something in the old web.xml.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP not picking up getAttribute from Servlet
 
Similar Threads
Problems when viewing specific description when search
JSP two pages
Servlet and XML result HTTP 404
Access database from a class file
Unable to find specific product