I have a doubt:
Is it possible to call a Java class with main() in JSP and print the value in console or JSP page (without use of a Servlet class)?
Similarly print the value in JSP page from Java class with main() (without use of a Servlet class)?
please need some explanation.
解决方案
Since a typical main() method has return type void, this cannot be done:
public staic void main(String[] args) { ... }
But you call any static method on that class and return a String and output that to your JSP:
Class
public class Util {
public static String doSomething() {
// do something and generate a String
return "helloWord";
}
}
JSP:
this prints out the return value of your static doSomething() method at where the JSP output tag is included.