I am using JDBC drivers in java action class file to access database in struts 2. But as mentioned on this website there is another way to access database in struts using tag in struts.xml file. But that is not working for me in struts 2. My question is is there any other more efficient way to access database in struts2 other than using JDBC drivers because I have to make connection each time I access any action class file? And I am not using hibernate only want to use Struts.
In a Java EE Web Application, database connections should be managed and pooled inside an EJB, the war should know nothing about the datasource or the database connection details.
If you can choose which technology to include in your Web App, I strongly suggest to let Spring manage your database connections.
Example of Struts2 + Spring integration.
Note: Spring libraries have nothing to do with Spring MVC, that is a framework alternative to Struts2.
Edit
Things change and nowadays for persistence / ORM I suggest pure Java EE's JPA2 over Spring.
Related
I am working on a web application which will serve as an SQL injection learning platform with multiple levels in spring boot and react. I am using PostreSQL as my main database, but I also wanted a lightweight solution for a vulnerable database on which the injections will occure. I was going to choose H2, but it isn't supported on Heroku where I wanted to deploy my application, as I worked with it in the past and it's already familiar.
So the question is: What other platform could I use to work with H2 or should I choose something else instead of H2, and if yes, what?
The way I handle this is to use spring-bean "profiles"
default
or
!default
I use H2 all the time for local-development mode (using 'default' spring bean profile to achieve this).
Now, we do not over-use spring-profiles. We have default and !default. And that is is.
All my JPA stuff works with H2.
I have a java web application which i'm developing using a local embedded HSQL database. Is there kind of a servlet which I can plug-in into my application and expose it /dbconsole, where I can fire sql statements, inspect tables, fields and table data?
I think you can try H2 Database which is a fast java opensource database. It can be easily embedded and it has a build-in servlet (org.h2.server.web.WebServlet) for db admin usage. We have used it in our production several years and it is very stable.
Here's its web console UI rendered by org.h2.server.web.WebServlet:
I've created a "framework/toolkit" for a specific type of database search. This was done with Spring-Data JPA using hibernate. This framework is usable by standalone desktop app or as a web application.
This framework ships with entity classes, Spring-Data Repositories and a transactional Service layer with optional method level security (spring-security annotations).
now I would like to create a web application using this framework. Since grails is from spring to and also uses hibernate I thought this might work but I'm open to other suggestions.
The entities in the web application will extend such provided by my framework and should use spring-data repositories extending repositories provided by the framework and services extending provided services for data access.
Or said otherwise I'm mainly interested in the scaffolding part (controller and CRUD web pages) and not the data access part. I'm open to any other tools that can achieve this.
Is this possible with grails? Other suggestions? Spring Roo?
I've been doing Java standard edition development for awhile, and the frameworks and solutions have been fairly obvious to me (Swing for GUI, etc). I've recently begun the task of building a server for my own needs and to host a web page (things the server will be doing in addition to hosting a web page would include personal SVN hosting and integrating more web functionality into existing and future applications). For coding for only a single computer (that is, distributed computing, etc. is not really a concern)- I'm not entirely certain between Spring, Hibernate and EJB and am not very knowledgeable as to the capabilities of each. Information would be appreciated. I know Spring is an alternative to EJB, and Hibernate is an object-relational mapping library, so does EJB combine the two?
EJB3 in summary consists of 3 bean types; Message Driven Beans, Stateless/Stateful Session Beans and Entity Beans or JPA (Java Persistance Architecture). Hibernate can be used as a JPA provider, but it doesn't have to be used that way.
Spring has functionality that is roughly similar to Message Driven Beans and Stateless/Stateful session beans but it does not have an equivalent to JPA. Instead it allows you to utilize JPA or hibernate directly but if you do combine Spring with JPA you'll need an EJB container.
Another difference is that EJB is provided by 'containers' whereas spring is a framework that can be deployed into a java se application or a java servlet container web application like jetty or tomcat. Its an important distinction to make. Tomcat is not an EJB container, only a servlet container, hence if you were to only use basic tomcat, you couldn't use EJBs but you could use spring by including the required spring jar files in your web application (WEB-INF/lib). In that case you wouldn't use JPA either but you could use hibernate.
Some java servers that ARE EJB containers include weblogic, websphere, jboss, geronimo, and glassfish. Tomcat can become an EJB container if you combine it with OpenEJB.
In an application i'm developing at the moment, I'm using tomcat + openejb so I have an EJB container so I can use JPA with OpenJPA as the persistance provider. I'm using Spring MVC to do the web application development and will most likely use spring security as well down the track. I probably will also use Stateless Session EJBs as well to encapsulate business functionality but i could just as easily use Spring service/dao beans instead of statless session ejbs as well.
Its pretty confusing sometimes to work out what parts of which framework or container you should use and really comes down to either preference or using functionality in one that doesn't exist in the other or ease of use. Another consideration is memory utilization. Some of the ejb containers consume large amounts of memory just starting up with no applications running. This is one reason I ended up using tomcat + openejb. Hope this helps.
Can i use Spring Webflow/MVC and Spring Security and Hibernate on Google App Engine?
Is there a list/summary of java frameworks that can be used on the GAE?
Will it Play In Java lists frameworks, languages and libraries that work (or not) in Google App Engine. At present, the information listed is:
Spring MVC
Version 2.5.6
Status COMPATIBLE
To see Spring's MVC framework running on App Engine, check out the autoshoppe sample application. If you're using Spring forms (e.g. using the spring-form.tld tag library and subclassing SimpleFormController), you will need to register custom editors for your properties. This is covered in http://groups.google.com/group/google-appengine-java/browse_thread/thread/d93fd7385bf85bf7.
Spring ORM
Version 2.5.6
Status COMPATIBLE
To get Spring working with the App Engine-provided JPA interface, follow the instructions at http://objectuser.wordpress.com/2009/05/19/spring-jpa-in-google-app-engine/, which discusses a workaround to the dependency on javax.naming needed for #PersistenceContext. A more complex workaround is available at http://groups.google.com/group/google-appengine-java/browse_thread/thread/187d41712ec1d394.
Spring Security
Version(s) ?
Status SEMI-COMPATIBLE
To work around a ClassNotFoundException, you can use a re-compiled version of the library which adds a StringInsensitiveComparator class -- the download is provided at http://www.google-app-engine.com/blog/post/Spring-security-fix-for-google-app-engine.aspx. See http://www.dotnetguru2.org/bmarchesson/index.php?p=1100 for tips on how to get Spring Security running with App Engine and GWT (in French). See http://groups.google.com/group/google-appengine-java/browse_thread/thread/964e7f5e42840d9c for discussion on the integration.
Hibernate
Versions All
Status INCOMPATIBLE
You cannot currently use Hibernate directly. The differences between the App Engine datastore and SQL were too great to get the standard Hibernate up and running under App Engine. App Engine does support JDO and JPA, so you may be able to convert your Hibernate code to use one of these ORM interfaces.
I suppose that it should work with Spring 3.0 too, I will try soon and share the results.
UPDATE: I tried a Spring MVC Hello World with Spring 3.0.6 with Google App Engine and it worked perfectly, both locally and in the cloud. The drawback though, is longer load time when a new instance starts.
As far as I know, no third party libraries are supported (at least none are listed), and JRE classes are limited to this list. But I guess if a library only makes use of the listed jre classes, they should be fine. However, finding out if they do would have to be based on trying it out.