SessionValue annotation.The application can be downloaded here:After downloading the JAR file, extract it and use Apache Ant to build a WAR file to deploy on Tomcat.
Once you have generated the WAR file, place it in Tomcat's
jar xvf 20080719annex.jar -- extract the JAR file
ant war -- generate a WAR file
webapps directory and start Tomcat. The application was developed using Java 6 and deployed on Tomcat 6.When the application is deployed, browse to the application (probably located at http://localhost:8080/annex if you are using the default settings). The following screen should greet you:

Clicking on the link will generate a random user and a random quote and place these two things on the session. After clicking on the link, the following screen will appear and display the random user and quote:

Click on the link to generate more random values.
The application is made up of two actions. The first action generates random data and the second action has the session data injected into it via reflection and the
SessionValue annotation.The following is the code for the
ReadSessionData action:
/////////////////////////////////////////////////////////
// ReadSessionData.java
public class ReadSessionData extends ActionSupport {
private User user;
private String message;
@Override
public String execute() {
System.out.println("\nReadSessionData found the following values:");
System.out.println("user: " + user);
System.out.println("message: " + message);
return SUCCESS;
}
public User getUser() {
return user;
}
@SessionValue(id = "user")
public void setUser(User user) {
this.user = user;
}
public String getMessage() {
return message;
}
@SessionValue(id = "message")
public void setMessage(String message) {
this.message = message;
}
}
The interceptor described in the previous post intercepts this action and injects the user and message dependencies with the values on the session that respectively have the IDs of
"user" and "message".

0 comments:
Post a Comment