• 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

servlet setting some value need to retrive that value in a normal java file

 
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 having a jsp page for submitting values .
All these values are recievied by a servlet .
This servlet in turn calls a normal java file
(This is the flow of our application)


Now the problem is

In that servlet i am setting some value for this i have to pass this value to that java class

For setting value inside servlet ,i have taken help of javaBean class as shown below


Inside servlet :


But when i am trying to retrive this inside my Java Class


It is returning me null .

Please help
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are actually passing the FlagBean instance that you created in your servlet to the java class?? I don't see any reason how this can happen
 
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
I am also not sure how to do this ?

so please tell me how can the communication from my servlet class to the java class can happen ??
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you could show us the bit of your code in the doGet or doPost that is related to the call to your worker bean?
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not clear what you are trying to do here, Are you trying to call some methods of a bean from the servlet or ...?
 
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

Ankit Garg wrote:So you are actually passing the FlagBean instance that you created in your servlet to the java class?? I don't see any reason how this can happen



thats why i posted .
 
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

Andrew Monkhouse wrote:Perhaps you could show us the bit of your code in the doGet or doPost that is related to the call to your worker bean?



Its nothing but a simple if condition .
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, you are creating the instance(DTO) in servlet and setting a value. where you are getting that? As vijitha said,explain your problem clearly,if you want to solve[get answare] your problem.
 
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

where you are getting that



Oh i am getting that inside my normal java class



But its returning me null .

Its a 3000 lines of code and relates to Spatial Data and Mapviewer , so could not post all that , so just explained in simple way .
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP 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:



Hmm.dont create a new instance . use the existing one(in which you set the value) .please google for "instance vs class"
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

so please tell me how can the communication from my servlet class to the java class can happen ??


Okay so in your servlet you are doing this

And in your java class you are doing this

And you are expecting the value sld or sdo to be returned?? You just created a new object in your java class, how will the value magically transfer from your servlet to the normal class?? Can you show us the code where you are calling the normal java file in your servlet. You'll need to pass the FlagBean instance that you create in your servlet to the normal java class for the value to be able to reach the normal java class...
 
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
i dont know that thank you i will try that on monday and let you know that status .

 
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'll need to pass the FlagBean instance that you create in your servlet to the normal java class for the value to be able to reach the normal java class...



so Ankit by the above you mean that , don't create new class of FlagBean inside the java class but just call the getter Method it (Am i right to understand this properly ?)


Inside my Java class

FlagBean fb = new FlagBean()

but just fb.getMethod()
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran V wrote:.... don't create new class of FlagBean inside the java class but just call the getter Method it (Am i right to understand this properly ?)
Inside my Java class
FlagBean fb = new FlagBean()
but just fb.getMethod()


You should call the getter of the object you have set the values in, perhaps passing that reference to your java class.
 
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 should call the getter of the object you have set the values in, perhaps passing that reference to your java class.



Hi i did as per you said but without creating an instance of FlagBean inside my second java class it is not compiling .

For example :



Its inot understanding what is meant by fb .
How can i do this ??
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lot of confusion over this one - so let me try taking up one point at a time,

Ravi Kiran V wrote:Hi ,

I am having a jsp page for submitting values .
--Sam - Right this works

All these values are recievied by a servlet .
--Sam - I think we are good up to this point too

This servlet in turn calls a normal java file
(This is the flow of our application)
--Sam - This is where the problem is - so lets clear up a few things.
There is no such thing as calling a Java File - unless you are using Runtime class to execute the file or something.

What you can do though is create an Object of the plain Java class and call a method or call static method of this plain java class and pass your bean as a parameter to the method!





It will be interesting to know what you are doing currently - I would suggest that you post your entire Servlet class if you are looking for more help!!
 
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
All of you thank you very much .

I have made all the methods and properties to static and its working (without creating an instance of that Bean class)
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring 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:All of you thank you very much .

I have made all the methods and properties to static and its working (without creating an instance of that Bean class)




Might work - but it could be a problem for a web application!! Does it work when you have more that one simultanous request?
 
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
seems interesting sam . ( I did not test for simultaneous requests actually )

But can you please tell me what will be the problem actually .
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring 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:seems interesting sam . ( I did not test for simultaneous requests actually )
But can you please tell me what will be the problem actually .



When you use static properties - you are just working with one copy of the variables. So if one request sets the value to 1 & another sets it to 2 the first value will get over written. Remember the container is going to span different threads to handle each incoming request - so you might end up with cases where you were expecting some value and ended up with another - and these kind of bugs might not even show up when you test the application under low load!


 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you do things in this way.
lets take an example :

suppose you have 1 text field named "myText" in jsp. you submitted form to your servlet in which you have called a java class.
Now myText comes in your servlet inside request object. you do 1 thing. pass this complete "request object" inside your java class constructor and assign it to instance variable and then use it in your methods.

some thing like this

Servlet side code:




MyClass side 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
Thank You sam for your nice explanatation

Gaurav i don't know that we can use HttpServletRequest inside a normal java class (That is our class without extending any Generic Or Http Servlet)
i will certanily this .

Thank you Java Ranch

 
gaurav kant
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can do. Just import javax.servlet.http.HttpServletRequest and use it. i am sure about it. It will ease your life
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why don't you pass the bean object (fb in your case)created in your servlet to your java class through constructor or method parameter of your java class and get the value from bean object.
 
gaurav kant
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

samir singha wrote:why don't you pass the bean object (fb in your case)created in your servlet to your java class through constructor or method parameter of your java class and get the value from bean object.



Both are the same things. either direct fetch values from request or do one more step in which first populate bean then use in another class. Do any way you think is good
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic