Spring, Struts 2 – part 2

Adding database management.

According to previous article, now I am going to show how to manage a database within our previous created web application.
The result is a very simple application, but I hope it will be useful to understand the way to perform similar tasks.

For this purpose, I will use:

* HSQLDB, a data leading SQL relational database engine written in Java, I think I’ll write an article about it as soon as possible..It is very interesting and powerful.
* Hibernate, ORM that no needs presentations!
* Spring Framework, especcialy Transaction Manager, I think that it is an underestimated feature of framework.

Our application will retrieve from database some records containing strings that will be printed in a jsp (they will print a classical Hello World message).

First Step: configuring HSQLDB database

Download latest version of hsqldb database, currently is 2.0.0 (rc9). Then I follow instructions from website and report here:

depending on platform you use (Windows or Linux or whatever you prefer) the procedure to be followed is almost the same.

* uncompress the zip folder downloaded from website;
* start HSQLDB server: under installation folder type ‘cd data’ and then ‘@java -classpath ../lib/hsqldb.jar org.hsqldb.server.Server %1 %2 %3 %4 %5 %6 %7 %8 %9’ (wait for completion of boot process);
* run an SQL client to connect to database server. I use MyEclipse IDE, but anyone can be used, the default connection parameters (if you just downloaded hsqldb package) are: connection URL jdbc:hsqldb:hsql://localhost/ , username SA , password ; for further configuration issues, I suggest to read HSQLDB wiki, it is very helpful and quick.
* Create new table with name HELLO, columns are: ID, PHRASE (ID must be set as numeric primary key, not nullable and incrementable, while PHRASE is a VARCHAR(15));
* Insert new records in that table (follow my same order): ID:1 – PHRASE:’Hello ‘, ID:2 – PHRASE:’World! ‘, ID:3 – PHRASE:’This data ‘, ID:4 – PHRASE:’is stored ‘, ID:5 – PHRASE:’in database ‘;

Second Step: configuring Hibernate project

This step is simple for me, making use of MyEclipse and I hope also for you, guessing the procedure to follow is similar.

First of all I create an external (referred in main one) project that will be used as Hibernate’s project, from my IDE I click on “Create new Java Project” and once it is created, I right-click on it and then “Add Hibernate Capability”. I give it the name: “hibernate-mapping”.

Libraries:

Typically, in creation window, the IDE ask to user for innformation about database, here you have to put connection url, username etc etc. Let to create SessionFactory.
Now is time to create mapping between database and POJO. With MyEclipse this thing is very simple:
Just, right-click on table you want to map (in our case is HELLO) -> Hibernate Reverse Engineering ->
In popup window select previously created project’s source folder (Hibernate project), select only “Create POJO”, select “Java Data Object” -> Finish.

Now you should have something similar to this:

Now we create a new Web Application (it is the same used in previous posted article, with a few of modifies) and import the hibernate project as dependency of this project.
This is our main project.
Main project integrates Struts2 and Spring and for this reason I suggest to read this to full understand the code shown below.
Action code:


package it.nickg.webapp.web.actions;

import it.nickg.webapp.services.HelloService;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport {

private HelloService helloService;
private List words;

public List getWords() {
return words;
}

public void setWords(List words) {
this.words = words;
}

public HelloService getHelloService() {
return helloService;
}

public void setHelloService(HelloService helloService) {
this.helloService = helloService;
}

@Override
public String execute() throws Exception {

words = helloService.getWords();
return SUCCESS;
}
}

Business service interface:


package it.nickg.webapp.services;

import java.util.List;

public interface HelloService {

public abstract List getWords();
}

Business service implementation:


package it.nickg.webapp.services.impl;

import it.nickg.hibernate.mapping.Hello;
import it.nickg.webapp.DAO.HelloDAO;
import it.nickg.webapp.services.HelloService;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

@Transactional
public class HelloServiceImpl implements Serializable, HelloService {

private HelloDAO helloDao;

public void setHelloDao(HelloDAO helloDao) {
this.helloDao = helloDao;
}

public List<string> getWords() {

List<Object><p>

phrases = (List) helloDao.getPhrases();

List<string> words = new ArrayList<string>();

for (Iterator<Object> iterator = phrases.iterator(); iterator.hasNext();){

String word = ((Hello) iterator.next()).getPhrase();

words.add(word);

}

return words; }

}

DAO Interface:


package it.nickg.webapp.DAO;

import java.util.Collection;

import org.hibernate.SessionFactory;

public interface HelloDAO {

public abstract void setSessionFactory(SessionFactory sessionFactory);

public abstract Collection<object> getPhrases();

}

DAO Implementation:


package it.nickg.webapp.DAO.impl;

import it.nickg.hibernate.mapping.Hello;
import it.nickg.webapp.DAO.HelloDAO;

import java.util.Collection;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class HelloDaoImpl implements HelloDAO {
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

public Collection<Object> getPhrases() {

Collection phrases;

Session session = this.sessionFactory.getCurrentSession();

phrases = session.createCriteria(Hello.class).list();

return phrases;

}

}

At this point, the essential point of integration, applicationContext.xml file. Adding this lines lets Spring to manage datasource:


&nbsp;

<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="myDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"></property>
<property name="url" value="jdbc:hsqldb:hsql://localhost:9001"></property>
<property name="username" value="sa"></property>
<property name="password" value=""></property>
</bean>

Then define Hibernate’s SessionFactory, within Spring management:


<bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" id="sessionFactory">
<property name="dataSource" ref="myDataSource"></property>
<property name="mappingResources">
<list>
<value>it/nickg/hibernate/mapping/Hello.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
</property>
</bean>

Now, let’s define Dependency Injection, briefly: inject SessionFactory into DAO, DAO into Service, Service into Action and applicationContext.xml will look as shown below:


<beans xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="myDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"></property>
<property name="url" value="jdbc:hsqldb:hsql://localhost:9001"></property>
<property name="username" value="sa"></property>
<property name="password" value=""></property>
</bean>

<bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" id="sessionFactory">
<property name="dataSource" ref="myDataSource"></property>
<property name="mappingResources">
<list><value>it/nickg/hibernate/mapping/Hello.hbm.xml</value></list>
</property>
<property name="hibernateProperties">
<value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
</property>

</bean>

<bean class="it.nickg.webapp.DAO.impl.HelloDaoImpl" id="helloDao">
<property name="sessionFactory" ref="sessionFactory"></property>

</bean>

<bean class="it.nickg.webapp.services.impl.HelloServiceImpl" id="helloService">
<property name="helloDao" ref="helloDao"></property>

</bean>

<bean class="it.nickg.webapp.web.actions.HelloAction" id="helloAction">
<property name="helloService" ref="helloService"></property>
</bean>
</beans>

BUT, if you try to run application an Hibernate exception will prevent it from working, because Transaction Management misses. There are many choices for Transaction management, I prefer to use the annotation-base approach, which requires to add this lines at applicationContext.xml:


<tx:annotation-driven transaction-manager="txManager">
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="txManager">
<property name="dataSource" ref="myDataSource"></property>
</bean>

</tx:annotation-driven>

Final applicationContext.xml will be:

and to add @Transactional over each (concrete) classes that make use of transaction; in our case these are the services’ ones. NOTE: at this point hibernate.cfg.xml can be deleted! Datasource definition and links are defined and handled through Spring configuration file, there is no more need of another external xml file. Add ‘@Transactional’ on top of HelloServiceImpl:


@Transactional
public class HelloServiceImpl implements Serializable, HelloService {

private HelloDAO helloDao;

public void setHelloDao(HelloDAO helloDao) {
this.helloDao = helloDao;
}

public List<string> getWords() {

List<object><p>

phrases = (List) helloDao.getPhrases();

List<string> words = new ArrayList<string>();

for (Iterator<Object> iterator = phrases.iterator(); iterator.hasNext();) {

String word = ((Hello) iterator.next()).getPhrase();

words.add(word); } return words;

}

}

JSPs, as explained in previous posted article, work in this way: index.jsp redirects to hellopage.action that, in turn, redirects to success.jsp. index.jsp:


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:redirect url="hellopage.action">
</c:redirect>

success.jsp:


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<s:iterator value="words"><s:property></s:property>
</s:iterator>

Result shown on web page is this:

I hope this article will be useful to someone, feel free to leave a feedback here.

Struts 2 – Spring integration

An introduction and web application example

Recently, There has been a lot of noise about Dependency Injection and Inversion of Control based frameworks, most of this due to this article of Uncle Bob.
I consider article of Martin Fowler about above-mentioned pattern somewhat like a “manifest” of Inversion Control\Dependency Injection, so I invite you to accurately read it.
But now, what about real, pragmatic, occupational impact of this technology on a Java developer?
What I can see is a broad diffusion of Spring framework, that is a great tool in my opinion, but a giant apart universe, too. Spring gives to team of developers the ability to decoupling entire project in separate parts, each one independent from each other and several sub-teams can work singly, without or with very poor knowledge about work of collegues on other parts.

Typically, each team work on a single level of a classic three-tiers architecture:

  • Presentation layer
  • Business Logic layer
  • Physical layer
But this rule is not written anywhere. Spring framework gives great support on integration and decoupling of project shares, but it has a price!
Gigantic overall configuration work (expecially if you integrate more frameworks\technologies), giant and multiple xml\properties files writing..well, in my humble opinion.. it seems a pachyderm to manage. Furthermore, code injected via xml is often difficult to debug. I am very sceptical that it is the panacea of all ills, the jolly to be used in every circumstance.
However, Spring helps very much in some cases, I never dream for a moment to criticize this wonderful product and the amazing work performed by community of developers.
My questions are: It is really helpful to you? Do you really save time and resources using that? How big your project is to justify that configuration and xml-read working?
For most project I worked on, Spring would involve to many resource and time to be spent and my response to above questions is No for all three  cases, BUT I am a very curious person and I like challenges; further more it is so required on market, that, sooner or later, I will massively use in professional environment. As they say on official documentation preface: Spring is modular, allowing you to use only those parts that you need”. Moreover I am very bewitched from Spring’s Transaction Manager, that I think, in general, is a survival module for every web application project.


Anyway, this is not an article on Spring, neither on Dependency Injection. I am going to show how to integrate two useful frameworks: Struts 2 and Spring.
I assume that the reader knows both technologies, one is a MVC Framework (most used for web development), the other is a “lightweight solution” to develop java enterprise applications.
Googling I found several workarounds and some of that they works only with specific version of above frameworks.
I tried out almost all the most published solutions to take this task and I found this one, that I’m going to explain in this article, the more efficient and easy to implement.
I know, a service locator can be used for this purpose instead of dependency injection or, better, we can do all the work within Spring framework, using Web Flow, but I think Struts 2 is a great tool for developing presentation tier of web applications and I prefer to use it over Web Flow.
Let’s go into practical side!

Wait wait!! ..marginal note: I switched to MyEclipse IDE since two months, I never loved Eclipse as IDE, too many configuration settings, not intuitive user interaction, very mnemonic use required, everywhere you click-right, a big menu will be open.. But MyEclipse rocks! Explosed deployment and plugins (dependency) management are features useful enough to motivate my emphasis on this tool.

Steps to be followed to configure your project for Spring and Struts2 support are simple in MyEclipse:
    just Right-click on project –> MyEclipse –> then first add Struts Capability, then Spring Capability. 
Remember to select version 2.1 of Struts core libraries and spring plugin (servlet default specification will be 2.5) and for Spring add 3.0 Core libraries and Web libraries specify the path where to put applicationContext.xml file: WEB-INF (but you can always manually move in future).

On other IDEs, I suppose there are other ways to add these supports to main project, the result, however, will be exactly this:

Fig. 1 Libraries included

and at the end of the file, first of tag closing, write:

This snippet of code sets a listener to use Spring as Struts action manager.


<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

so web.xml file will look like this:


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <filter>
 <filter-name>struts2</filter-name>
 <filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
 </filter>
 <filter-mapping>
 <filter-name>struts2</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 <welcome-file-list>
 <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 <listener>
 <listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
 </listener>
</web-app>

Now, let’s create a Struts action; in our example it is used to retrieve some information from a service  on business layer and push it in a jsp.
Again, I am going to show only how to integrate two frameworks, so:
 – Jsp will be very ugly;
 – Project will not be extended to physical layer (no database use and interaction);

Tutorials on these missing features will be submitted in the near future (I am writing several articles on Hibernate and JQuery).

Our application uses a Struts Action to call an interface of a concrete implementation of a service and then, through action, it whows results to a JSP.
Here the UML code:

Struts Action code:


package it.nickg.webapp.web.actions;

import it.nickg.webapp.services.HelloService;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport {

private HelloService helloService;
 private List words;

public List getWords() {
 return words;
 }

public void setWords(List words) {
 this.words = words;
 }

public HelloService getHelloService() {
 return helloService;
 }

public void setHelloService(HelloService helloService) {
 this.helloService = helloService;
 }

public String execute() throws Exception {

words = helloService.getWords();
 return SUCCESS;
 }
}

Struts2 apply dependency injection through setters, so every variable that you need to use in jsp, must have a setter (and I add getter too).

HelloService Interface code:


package it.nickg.webapp.services;

import java.util.List;

public interface HelloService {

public abstract List getWords();

// mandatory setter method for Spring's dependency injection
 public abstract void setWords(List words);
}

HelloServiceImpl, real service implementation:


package it.nickg.webapp.services.impl;

import it.nickg.webapp.services.HelloService;

import java.io.Serializable;
import java.util.List;

public class HelloServiceImpl implements Serializable, HelloService {

private List words;

public List getWords() {
 return words;
 }

public void setWords(List words) {
 this.words = words;
 }
}

Spring applies injection to setter, too: when you need to return some variable from a method in middle-tier, just declare it as private and define a setter, then in xml spring’s configuration file define values to be setted. Spring inject values and presentation tier doesn’t need to know real implementation of business object.

Now edit struts.xml file to map the action created:


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="hello" class="helloAction">
<result type="success">/result.jsp</result>
</action>
</package>
</struts>

<h3><span style=”font-size: small;”><strong>Crucial  note: what allows to estabilish the link between Struts and Spring is here, <em>class </em>parameter of action must be set as <em>id </em>of spring’s bean calling that action<span style=”font-size: x-small;”>.</span></strong></span></h3>
Add this code to applicationContext.xml file


<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:p="http://www.springframework.org/schema/p"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="helloService" class="it.nickg.webapp.services.impl.HelloServiceImpl">
 <property name="words">
 <list>
 <value>Hello </value>
 <value>World! </value>
 <value>This is </value>
 <value>a Struts - Spring </value>
 <value>integration example</value>
 </list>
 </property>
 </bean>

 <bean id="helloAction" class="it.nickg.webapp.web.actions.HelloAction">
 <property name="helloService" ref="helloService"/>
 </bean>
</beans>

Now we write JSPs. Let’s give to index.jsp the role to redirect to our action:


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:redirect url="hellopage.action"/>

and write the “success.jsp” in order to display data returned from action:


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
 + path + "/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>">

<title>My JSP 'success.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

</head>

<body>
 <h3>This is only a sample</h3>
 <s:iterator value="words">
 <s:property/>
 </s:iterator>
 </body>
</html>

When you run the application, it goes to index.jsp, redirected to hellopage.action and from here to success.jsp that displays an output like this:

In the next article, I will start from this application and I will extend it to physical layer, adding a database and an ORM implementation.

Stay tuned!

Struts2 and Netbeans, configuring latest versions.

Configuring Netbeans to work with Struts2 framework

In this article I provide a workaround to let configure Netbeans Web Project, supporting Struts2 framework. Searching on the web, with Google and not only, I found an official plugin for Netbeans IDE, in developing status; but, sadly, last update was on 2008.

There is a blog , whose author provides an updated version of official plugin (it is modified for netbeans 6.7 and Struts 2.1.6) and this could be useful enough for my purpose…but maybe for curiosity or obduracy, I have created this workaround for installing and configuring a development environment, always updated to latest versions of both IDE and framework.

Very quick overview on Struts2 for those who already know Struts

Most revolutionary innovation provided by Struts2 is related, beyond a shadow of a doubt, with most important method in every Action: execute() method.
Unlike first version of Struts, in Struts2 this method is implemented without parameters to be passed;
and so anyone should ask: how to get the object which we need to work with?
With Struts, this is possible through Form beans, ActionForm. With Struts2, this becomes possible thanks to a specific pattern, known as inversion control or dependency injection.
I don’t pretend to dwell on a theoric explanation about this pattern, but for most curious of you, I warmly suggest to read  this interesting article, written by Martin Fowler.

Every way, this is the pattern which Spring framework is known for.

Struts2 complies to an advanced interpretation of MVC paradigm: pull-MVC. The purposes of this article are far away from an exhaustive text on differences between Struts and Struts2, you can find a lot of readings about this issue, with a quick Google search.
Anyway, some of this differences between two frameworks are fundamental, in my opinion.
MVC schema



Actions play a difference role, they pass from Controller to Model and View’s layers are now able to pull data directly from the actions, there is no more need of an extra object of model layer. The framework is based on 5 main components:
Model
    – Action;
Controller    
    – Interceptors;
    – DispatcherFilter;
View
    – Result type;
    – Result view (representation of results);
    – Valuestack\OGNL (modules that make possible integration between other components).
Who works with Struts knows very weel that one of the main configuration file used by framework is web.xml. References to several modules that builds the framework are defined inside that.
Let’s go with practical part.

Creation of a Web Project supporting Struts2, with Netbeans

The first step is to create e new empty WebProject:

File –> New –> Project 

From Categories choose Java Web and, on the left, Web Application. Then Next.

In the next view, give a name to the project, now select an Application Server and in the last page leave unchecked the Struts2 support . Then Finish.

At this point add Struts2 libraries to the project:
right click on Libraries and  Add Jar\Folder.
Now choose which libraries to include in the project, I personally suggest to begin including only necessary ones:
struts2-core.jar
xwork.jar
ognl.jar
freemarker.jar
commons-logging.jar
——————–
commons-io.jar
commons-fileupload.jar
imported libraries

It seems that adding all of those it is not a good idea, because they can generate conflicts. Last two libraries listed above became essential since version 2.1 of struts, I’ll investigate on that.

Creation of web.xml file.

Next step is writing web.xml file.

In particular, it is all handled through filters definition. It is necessary to add an entry for FilterDispatcher:That is the class that behaves like servlet filter, it initializes the framework and manages requets.
This file can be easily edited using the tab General, in this way:
Open it, select tab Filters –> Add Filters Element

In filter name field type: Struts2In filter class field, we should enter the FilterDispatcher class, who handles requests filtering. But the API of this class indicates:

Since Struts 2.1.3, use StrutsPrepareAndExecuteFilter instead or StrutsPrepareFilter and StrutsExecuteFilter if needing using the ActionContextCleanUp filter in addition to this one

Hence, since Struts 2.1.3, in filter class, inside web.xml, you should add:apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

The reason of this is still a mystery for me, until the official documentation on
versions subsequent to 2.1.3 will not be updated.

Inside Filter Mappingapply to URL: /*

Final xml will be something like this:


<web-app version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <filter>
 <filter-name>Struts2</filter-name>
 <filter-class>apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>
 <filter-mapping>
 <filter-name>Struts2</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 <session-config>
 <session-timeout>
 30
 </session-timeout>
 </session-config>
 <welcome-file-list>
 <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

Creation of struts.xml file.
Struts.xml file, in version 2 of Struts, replace struts-config.xml. Here it is the template, very basic, for every project.

Go in Source Package directory and create a brand new xml with a simple right click, then type:
</div>
<div style="margin-bottom: 0; margin-top: 0;">

<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>
 <package name="default" extends="struts-default">
 </package>
</struts>

I experienced several problems when deploy the application and I solved them creating a directory (manually) named classes inside the WEB-INF one (it can be done easily within Netbeans) and putting inside there the struts.xml file.

Now It is all ready to run you first application, It would be very interesting to delve into other configuring issues of Struts2, for example the properties files. But in this context, they can be left empty.

If you want to create your first Struts2 application, I refer you to documentation on the
official site
.

References:

An italian version of this article is available here:

Wellnet lab

Welcome, folks!

Welcome to my brand new blog!

You’ll probably say: why another blog on Java, developing, frameworks and others things like these?
My answer is: because I need it!
I love my job and I’ve been interested in Information Technology, Software Engineering, Unix-like Operating Systems and so on for a long time and now I work on these fascinating things, but..lately I really have short free time to upgrade my knowledge and it is frustrating!


Every time I say to myself: “I’ll study this new technology next weekend” or “Interesting! I’ll expand on that”…
And then..Nothing! I have never kept those promises, due to short time..but due to my laziness, too!


So.. with this blog I hope that I will be more motivated to study and I will not put off my good intentions.

I’m fighting my laziness. Please, help me to defeat it!