Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jsp文件和资源类之间的连接_Java_Jsp_Rest_Jersey - Fatal编程技术网

Java jsp文件和资源类之间的连接

Java jsp文件和资源类之间的连接,java,jsp,rest,jersey,Java,Jsp,Rest,Jersey,我的示例是使用隐式可视配置特性(请参见WEB-INF/WEB.xml)和隐式可视方法,其中JSP页面通过放置在右侧进行映射 与相应的资源包名称对应的路径。它不起作用。我应该做什么作为额外的 若${it.name}被写入jsp文件,并且资源类也有它的私有名称变量,那个么什么也不会发生。我无法实现连接 这里是web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java

我的示例是使用隐式可视配置特性(请参见
WEB-INF/WEB.xml
)和隐式可视方法,其中JSP页面通过放置在右侧进行映射 与相应的资源包名称对应的路径。它不起作用。我应该做什么作为额外的

${it.name}
被写入jsp文件,并且资源类也有它的私有名称变量,那个么什么也不会发生。我无法实现连接

这里是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">
    <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>

Jersey Web应用程序
com.sun.jersey.spi.container.servlet.ServletContainer
com.sun.jersey.config.feature.Redirect
真的
com.sun.jersey.config.feature.ImplicitViewables
真的
1.
伺服适配器
com.sun.jersey.spi.container.servlet.ServletContainer
1.
Jersey Web应用程序
/
伺服适配器
/资源/*
com/sun/jersey/samples/bookstore/resources/Hotelstore/index.jsp
下面是com/sun/jersey/samples/hotelstore/resources包中的hotelstore.java/

@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.
......
}
@Path(“/”)
@独生子女
公共级酒店{
私有最终映射项=新树映射();
私有字符串名称;
公共酒店{
setName(“奥特雪利顿”);
getItems().put(“1”,新酒店(“Sheriton”,“Maslak”,“Big boss”),新房间[]{
新房间(1,“Cedric”、“dolu”),
新房间(2,“埃格纳”、“多鲁”),
新房间(3,“德利”、“多鲁”),
新房间(4,“bos”)
}));
}
@路径(“Hotelitems/{itemid}/”)
公共Hotelitem getItem(@PathParam(“itemid”)字符串itemid){
Hotelitem i=getItems().get(itemid);
如果(i==null)
抛出new NotFoundException(“没有房间号”+itemid);
返回i;
}
公共长getSystemTime(){
返回系统.currentTimeMillis();
}
公共地图getItems(){
退货项目;
}
名称的getter setter。
......
}

请发布您的web.xml,否则无法理解什么是“隐式可视配置”。你在用玻璃鱼吗

关于您的第二个问题,${it.name}假设您在pageContext中有一个绑定了名称“it”的bean,并且它有属性“name”——这意味着它有一个方法

public String getName(); // guessed the string, but its the obvious choice.
如果您能提供更多信息,那将很有帮助

我得到了一个404“未找到资源”,代码相同。我不确定您是否获得相同的HTTP状态代码。 我下载了书店示例,发现使用了HTTP过滤器而不是HTTP Servlet。我也做了同样的改变,效果很好。 尽管如此,在我的应用程序中使用HTTPservlet或过滤器并没有什么区别。我正在考虑记录jira请求。 我正在使用Jersey 1.1.5.1和Spring插件