views:

421

answers:

3

My example is using the ImplicitViewable configuration feature (see WEB-INF/web.xml) and implicit viewables approach, where the JSP pages are mapped via being placed at the right path corresponding to the appropriate resource package name. It doesn't work. What should I do as an extra?

if ${it.name} is written into jsp file also resource class has its private name variable then nothing happens. I couldn't achieve the connection.

here is web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.feature.Redirect</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.config.feature.ImplicitViewables</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>com/sun/jersey/samples/bookstore/resources/Hotelstore/index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

here is hotelstore.java inside of the package com/sun/jersey/samples/hotelstore/resources/

@Path("/")
@Singleton
public class Hotelstore {
    private final Map<String, Hotelitem> items = new TreeMap<String, Hotelitem>();

    private String name;

    public Hotelstore() {
        setName("Otel sheriton");
        getItems().put("1", new Hotelitem("Sheriton", "Maslak","Big boss", new Room[]{
        new Room(1,"Cedric","dolu"),
        new Room(2,"Eigner","dolu"),
        new Room(3,"Deli","dolu"),
        new Room(4,"","bos")

        }));

    }

    @Path("Hotelitems/{itemid}/")
    public Hotelitem getItem(@PathParam("itemid") String itemid) {
        Hotelitem i = getItems().get(itemid);
        if (i == null)
            throw new NotFoundException("there is no room number"+itemid);

        return i;
    }
    public long getSystemTime() {
        return System.currentTimeMillis();
    }

    public Map<String, Hotelitem> getItems() {
        return items;
    }
     getter setter for name.
......
}
A: 

Please post your web.xml, otherwise it is not understood what is the "ImplicitViewable configuration". Are using glassfish?

regarding to your second question, ${it.name} assumes you have a bean in your pageContext bound with the name "it" and it has the property "name" - meaning it has a method

public String getName(); // guessed the string, but its the obvious choice.

If you can provide more information it would be helpful

David Rabinowitz
A: 

hi, a post in french on this topic http://www.opikanoba.org/java/rest-jersey-jsp

fred
A: 

I got a 404 "resource not found" with the same code. i am not sure if you got the same HTTP status code. I downloaded bookstore example, and found that HTTP Filter was used instead of HTTP Servlet. I did the same change and it worked. Although, it makes no difference in my application to use http servlet or filter. I am thinking of logging a jira request. I am using Jersey 1.1.5.1 with Spring plugin

zsundeep