开发者

Different ways of creating an instance of class

What are the different way a bean can be created in web development? I know we can use <jsp:useBean />, <bean:define />, or JSON format. Are there more choices? What are their advantages or disadvan开发者_开发问答tages?


I know that this may sound harsh, but if you are creating beans in a jsp page, you're doing it wrong. jsp:useBean and friends are holdovers from the bad old days.

If you aren't already, you should be using a sever-side MVC framework - Spring is good, Struts will work. The 'controller' or 'action' of your framework should then expose the required beans to the jsp page. The jsp page can then access them via jstl.

By no means should you be writing any Java code in a jsp, and that includes invoking methods of a bean defined with jsp:useBean.

Also, JSON creates javascrript objects, not java objects. This is a fundamental and very important difference. If you don't understand the difference, I urge you to go back and read a bit more until you do understand the difference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜