28
Dec/11
5

App Engine + JSP + Jersey Viewable Example

I’m putting together a simple App Engine webapp that’s using Jersey as the controller and JSP for the view. Wrapping a Jersey Viewable in a Response, provides a clean way to do this, but I had a bit of trouble getting everything wired up properly. After a little googling I found a post over at Don Park’s Daily Habit that helped me get things right. Here’s a full working example for anyone who’s trying to do the same thing:

Required JARs

I’m using Jersey 1.11

  • asm-3.1.jar
  • jersey-core-1.11.jar
  • jersey-server-1.11.jar
  • jersey-servlet-1.11.jar

web.xml

<!--?xml version="1.0" encoding="utf-8"?-->
 
		JaxRsApplication
		com.sun.jersey.spi.container.servlet.ServletContainer
 
javax.ws.rs.Application
example.JaxRsApplication
 
com.sun.jersey.config.property.JSPTemplatesBasePath
/WEB-INF/jsp
 
com.sun.jersey.config.property.WebPageContentRegex
/(images|js|styles|(WEB-INF/jsp))/.*
 
		JaxRsApplication
		/*

JAX-RS Application

package example;
 
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
 
public class JaxRsApplication extends Application {
 
	@Override
	public Set&gt; getClasses() {
 
		Set&gt; classes = new HashSet&gt;();
		classes.add(HomeResource.class);
		return classes;
	}
}

Root Resource

package example;
 
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import com.sun.jersey.api.view.Viewable;
 
@Path("/")
public class HomeResource {
 
	@GET
	public Response get() {
 
		Map model = new HashMap();
		model.put("word", "World");
 
		return Response.ok(new Viewable("/home", model)).build();
	}
}

/WEB-INF/jsp/home.jsp

<!--?xml version="1.0" encoding="UTF-8"?-->
Hello ${it.word}
Comments (5) Trackbacks (0)
  1. Hello,

    Thanks for your guidance. I followed each and every step which have been listed. But it is saying that requested resource not found.

  2. I pay a visit everyday a few blogs and blogs to read articles or reviews, except this
    blog offers feature based articles.

  3. “I will certainly win the” For JORDAN FAMILY, is commitment when young, is to become the strongest commitment are extremely harsh tempered, is the pursuit of victory desire. With this spirit, their own achievements today, but also to bring this spirit Flight Camp Youth Basketball elites from three places. Today, these children will understand: triumph, it is to decide by themselves.

  4. I’ve been exploring for a little for any high quality articles or
    blog posts in this sort of house . Exploring in Yahoo
    I ultimately stumbled upon this web site. Reading this information So i’m happy to show that I have an incredibly good uncanny feeling I discovered exactly what I needed.
    I most surely will make sure to do not put out of your mind this website
    and give it a look on a relentless basis.

  5. Excellent post. I used to be checking constantly this blog and I am inspired!
    Extremely helpful info specially the closing section :
    ) I take care of such info a lot. I was seeking this
    particular information for a very long time. Thanks and good luck.

Leave a comment


No trackbacks yet.