How to Declare a Class and Instantiate an Object in JSP
Joined: Dec 20, 2003
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???
Joined: Jan 07, 1999
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?
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
Joined: Jul 02, 2003
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 email@example.com