Struts-在 struts 2 中连接 Mysql 的最佳方式?
无法确定在struts中连接mysql数据库的最佳方式是什么。
- 我们总是可以使用
DriverManger
和Class.forName()
来连接。 DataSource
接口 - 但这有问题,我收到编译错误数据源 dataSource = (DataSource)context.getAttribute(Globals.DATA_SOURCE_KEY); 或者使用
Action.Data_SOURCE_KEY
时。搜索时,我发现这些变量已被降价。
我如何在struts中使用连接池?放置数据库的url、用户名、pass的最佳位置是什么?我仍然必须在struts-config中以相同的方式使用数据源配置吗?那么这个设施为何被废弃呢?
问题太多,但我找不到学习struts的明确来源。 Struts doc 可以,但是修订和后台兼容性是学习者不容易得到的问题...请推荐一个学习 struts2 的好资源。
Unable to determine what is the best way to connect to mysql database in struts..
- We can always use
DriverManger
andClass.forName()
to connect. DataSource
interface - but this has problems I am getting compliation error forDataSource dataSource = (DataSource)context.getAttribute(Globals.DATA_SOURCE_KEY);
or whenAction.Data_SOURCE_KEY
is used. when searched I found that these variables are depricated.
How can I use connection pooling in struts?What is best place to place url,username,pass for database?DO i still have to use datasource configuration in same way in struts-config? Then why was this facility depricated?
Too many queastions but I cannot find a definite source to learn struts.
Struts doc can be but then revisions and backword compatibility are the issues which a learner cannot get easily... Pls suggest a good source to learn struts2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Struts 是一个MVC 框架,而不是一个数据库访问框架。您应该为数据访问层使用某种排序工具。 Spring 使管理连接、事务和排序变得非常容易,并且与 Hibernate 或 JPA 实现等 ORM 工具很好地集成。
Struts 适合这一点的地方在于,它将管理请求,委托给一个操作,而该操作又将调用使用您的数据访问层的服务。你可以将 DAL 放入你的操作中,但我不会——我会将它们放入服务中。
Struts is an MVC framework, not a database access framework. You should use some sort tool for your Data Access Layer. Spring makes it really easy to manage connections, transactions, and the sort, and integrates well with ORM tools like Hibernate or the JPA implementation.
Where Struts fits in in this is that it will manage the request, delegate to an action, which in turn will invoke a service that uses your data access layer. You could put your DAL in your actions, but I wouldn't -- I would put them in a service.
Struts 是一个采用MVC 方法的框架。它使您能够以有效的方式创建应用程序。与其他连接相比,数据库之间的连接存在一定风险。
Struts is a framework having the MVC approach. It makes you to create application in an efficient way. Connection between database is somewhat risk compare to someother connection.