I want to create a simple program in jsp .I want to create a class and then assign its methods to a object.How can I create a class and also a object from that class??
Asked
Active
Viewed 2,272 times
1 Answers
1
You can't create a public
or default
class in jsp. Remember all jsp files are compiled dynamically into servlets
. All the code you write in scriptlet
will go to service()
method of compiled servlet.You know you can't create class inside method right?? But it's possible to create an inner class.You can create an object for a class like you do in normal classes.Its better to create class in classes folder(or sources folder if you are in ide) then create object in jsp file and use the functionality.Like you always do in regular classes.
For more clarification refer java docs.
But it is considered as bad practice to write java code in jsp pages for more details see here

Community
- 1
- 1

udaybhaskar
- 159
- 5
- 16
-
I haven't figured out where I have to create the class.I got that I can't create a class inside jsp then where?? – ath j Jul 05 '16 at 09:22
-
If you are using ide create one class in sources folder create object in jsp. Please accept the answer if it helped – udaybhaskar Jul 05 '16 at 09:26