[Miles' Blog]

Welcome 2 My Planet

Available categories: [/] [working on downwap.] [trouble shooting] [working on Yup Mailman]

没有package的bean在jsp中的应用 [Permalink]

Fri Jun 25 14:07:50 CST 2004
Category [development. ~]

今天有人问我一个问题,说是他的bean怎么也无法在jsp中使用。我看了代码,没什么问题。拿来一试,果然不行。。经过调试发现,只要没有package,就有问题!仔细想想,以前好像也遇到过,不过当时因为赶进度,加了package就过了,没有回头多看。

这次时间充裕,上网找了一下资料。终于找了一个看上去比较合理的解释:

When you put the bean class files in the WEB-INF/classes dir, they are automatically in the CLASSPATH. You don't have to do anything special.

Having said that, when you put bean classes in the WEB-INF/classes, the whole Java world knows that these are beans without any package stmts, right!

Now there is a sticky thing with no-package bean classes.... /images/emoticons/sad.gif . When you use bean without a package stmt, the App Server will look for the bean class in the same package as that of the generated Servlet code. And we don't know what package the generated servlet code is, so generally the JSP fails.

Bottomline, put your beans in a package and then access them. Ofcourse in this case you will put the bean class files in the WEB-INF/classes/mycom/mypackage/ directory which reflects the package stmt in your bean class.

Posted by: miles
Comments [0] |

?
三月 2024
Sun? Mon? Tue? Wed? Thu? Fri? Sat?
     12
3456789
10111213141516
17181920212223
24252627282930
31      
<  Feb???Today??? Apr  >
<< <   1   > >>

Available categories: [/] [working on downwap.] [trouble shooting] [working on Yup Mailman]

Powered By blojsom?? RSS Feed? RSS2 Feed? RDF Feed

html hits:?38565