实例化jsp scriptlet之间的类 [英] Instantiating classes between jsp scriptlets
本文介绍了实例化jsp scriptlet之间的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以实例化一个类,然后在JSP中的scriptlet之间调用它的方法? 我遇到错误,我不知道为什么(java类和方法很好). 还有其他方法可以做到这一点(我只想从类中的方法中获得一个字符串)?
Is it possible to instantiate a class and then invoke its methods between scriptlets in JSP? I am getting errors and I don't know why (java class and methods are fine). Any other way to do the same (i just want a string from a method in a class)?
推荐答案
当然可以.您可以像这样为类创建对象,并在JSP的scriptlet之间访问它们的方法.
Yes of-course. You can create objects for your classes and access their methods between scriptlets in JSP like this.
<%
Foo foo = new Foo();
foo.method1();
%>
另一种方法是使用jsp的useBeans实例化类并在scriptlet中访问其方法
Another way of doing this is using useBeans of jsp to instantiate the class and access its method in scriptlet
<jsp:useBean id = "foo" class = "Foo" />
<%
foo.method1();
%>
这篇关于实例化jsp scriptlet之间的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文