• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to transfer Objects from JSP to a Servlet?

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I am displaying the Employee Records from DataBase into a JSP
I mean the Employee means , its a bean with properties as EMPID , EMPNAME , EMPAGE , EMPDEPT .

I am making a query to Database from my servlet and when data is stored i am storing all the records in a ArrayList , and forwarding this ArrayList to a JSP Page to print them .

Upto here its working fine .

After dipslaying this Employee Data inside the JSP Page , the user can modify the Employee details and clicks on save it should update the Modified data in Database , here i need to transfer the whole modified DTO of Employee Object .

Please tell me how can i transfer the Employee Object to servlet from my JSP Page ??

Please share your ideas , thnaks in advance .

Thanks in advance .

 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can store the Employee Object in request/session/application in jsp and get it from servlet and save it.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely the form submit goes to a servlet, not to a JSP? If it currently does go to a JSP, then you should rewrite it to use a servlet instead - JSPs are part of the view layer, they should not contain any logic or even DB access code.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can store the Employee Object in request/session/application in jsp and get it from servlet and save it.



I didn't get the approach you are suggesting .

After making chnages and clicks on Update Button , i have a function named as updateEmployee() inside my jsp

Now please tell me how can i send this Modified EMployee DTO into this function ??

function updateEmployee()
{

// Need your help here ??
}

Thanks inn advnace .
 
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran V wrote:

You can store the Employee Object in request/session/application in jsp and get it from servlet and save it.



I didn't get the approach you are suggesting .

After making chnages and clicks on Update Button , i have a function named as updateEmployee() inside my jsp

Now please tell me how can i send this Modified EMployee DTO into this function ??

function updateEmployee()
{

// Need your help here ??
}

Thanks inn advnace .




I think you should reframe your question. As we all know JSP is RESPONSE. Means once the response has been arrived to the browser, it's been treated as HTML by the browser. So in my opinion you can't pass Object from JSP to Servlet. Because at the browser end we can only talk about html not jsp.

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


I didn't get the approach you are suggesting .

After making chnages and clicks on Update Button , i have a function named as updateEmployee() inside my jsp

Now please tell me how can i send this Modified EMployee DTO into this function ??

function updateEmployee()
{

// Need your help here ??
}

Thanks inn advnace .




Looking at the code, I'd say updateEmployee() is a javascript function. Maybe inside this function is where we try to send the data to the server using forms. And in the jsp/servlet end, we parse the sent data and translate it to the intended javabeans.

Maybe something like this:



But somethings not quite right here..you should'nt use JSP for your parsing and logic.. In MVC, JSPs are for view only. So might as well move your logic inside a servlet.

Thanks,
Ian
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks , i have found an another way for doing this .

May be helpful to some others with same requirement .

While display data , i am displaying them inside the TextFileds and when submit button is made the form is mapped to an appropiate servlet , which takes care of submitting data to Database .

Thanks for your help .
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic