• 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 Declare a Class and Instantiate an Object in JSP

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to declare a Class and i want Instantiate a Object and assign some values to the attributes of the Object and then pass the Object to a Servlet. Can anyone please Help me out???
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid I don't really understand what you are asking.
I want to declare a Class and i want Instantiate a Object and assign some values to the attributes of the Object
So far this just sounds like regular Java. Write the source code for your class, compile it, and place the resulting class file in WEB-INF/classes. Then you can create an instance in your JSP using something like <% MyThing thing = new MyThing(); %> and assign things to attributes by either setting public fields <% thing.name = "whatever"; %> or using "bean syntax" <% thing.setName("whatever"); %>
and then pass the Object to a Servlet
This is what puzzles me. A servlet is essentially just a handler for HTTP requests. It accepts a request, reads parameters etc., does some processing, and produces a resulting web page. You can't expect to pass an object to a servlet.
Can you explain a little more about what you want this "servlet" to do with your object once you have "passed" it from your JSP?
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
You can create a class and after compiling it can place in WEB-INF/classes folder and in jsp file u can create object of that class using following jsp tag
<jsp:useBean id="object_name" class="class_name" scope"session/page/application/request"/>
<jsp:setProperty name="object_name" property="*"/>
<% =object_name.get_method_from_ur_class_file() %>
Check List
1. ur id and name should match
Bye
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello..
Frank Carver is very right and his solution is very feasible rather than creating a bean just for nothing ...
or would rather suggest to elaborate your question that would be more feasible to be answered....
any java programmer knows to make a class object and instantiate the variable and use the methods of the class ...
its very simple and jsp is not other thing than java its also a java code
for more queries..always welcome
vijay shah
v.shah@portlog.com
 
reply
    Bookmark Topic Watch Topic
  • New Topic