Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can we write main() in jsp

 
srinivas mallabathula
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can we write main() in JSP?then how it will execute?
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but why in the world would you want to do this?
You can put a main method in a jsp just like you can put any other method. The purpose of it eludes me, however. Especially since scriptlets are bad practice.

A JSP is just a kind of servlet, you know. A servlet is a java class. You can put a main method in at will. There's just no point to it.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could not use a main() method for any kind of testing because a JSP depends on executing in the servlet container environment with a request and response , etc etc objects created by that environment.

Testing outside the servlet environment can be very helpful but you need to write classes that don't depend on the container.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!