• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Pass data from Java servlet to JSP

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have been working (and stubbling) on a website for a while. A major problem that I have is to pass data between the server and client. From client to server I often pass data from forms, but when not doing this, I try to use jquery $.ajax() calls. With ajax, I am able to reliably pass date from client to server, but I have not yet settled on a reliable methodology to pass data from the server to the client.

To pass data from the server to client, I have looked at the web page at https://www.programmergate.com/pass-data-servlet-jsp/ and have been working with the first suggested method, "Using request attributes". I put together a simple web page using Apache tomcat as my local server with a simple example with 2 tests. All worked fine. [Note: the full version of the serlvet and the 2 JSP pages are attached. I can make the full example available if necessary.]

In test case 1, the servlet calls: . On the client side, the JSP code is:



Test case 1 works in all cases.

In test case 2, the JSP page has a form. The action for the form is to pass an email address entered in the form to the servlet. The servlet does a getParameter to read the value passed and then saves the value in a javabean. The servlet fetches the java bean value and passes the value by setting a request attribute as follows:



On the client side, the JSP code is:



Test case 2 works in it's original state.

I cleaned up and removed the javascript alert statements that I was using during development. I was surprised to find that when the alert statements were commented out, test case 1 work as expected, but test case 2 failed to pass data from the server to client. I don't understand why this would happen.

Can anyone explain this behavior or suggest what is wrong?

Thanks,

Jim A
 
Jim J Anderson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please consider this topic as closed. I may re-post it in the near future, but I think it may be revolved already. My explanation follows.  If reading this, you are probably better off leaving this topic now.

For the curious, I have an unusual set of events in the past 6 hours and my explanation for closing this follows.

Late last night, I wrote up this topic. I thought I hit the 'submit' button (actually, I'm 99.99% sure I did hit the submit button). I woke up early this morning and was anxious to see if anyone had responded. So I got back to my desk and looked at 'my posts'. The most recent thread I found was from last week. I realized that THIS topic had not been posted, so I hit the 'submit' button again and verified that it got posted.

I then reviewed and found a new reply had been posted for the topic that I posted last week. It was excellent guidance for me and I plan to implement the suggestion. I am hopeful that by following the suggestion and restructuring the control of my test website, it will resolve many issues that I have, including the problem documented in this thread.

Had I read the update to last weeks topic first, I never would have posted this thread. My apologies.

If it turns out that the underlying cause is not fixed when I restructure my sample web site, I will then re-open this or more likely, just recreate it.

Jim
 
Saloon Keeper
Posts: 6932
164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




This should just be



 
It's exactly the same and completely different as this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic