Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing ServletContext attribute from Action Class.

 
wai chun chor
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a Struts 2 application where a servlet runs on startup, it saves my datasource config into a servletContext:


The problem is I could not get this value from my action class where i need this datasource connection.

Any help is appreciated.
 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

try this in your action
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not better approach set as dataSource in webserver.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts Action objects are part of a Struts-based Controller. Ideally, you should not want to connect or access a data source from the Controller, i.e. Action objects.

As a treat, below is how to get the ServletContext object

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic