Java 如何构建两个Wicket应用程序

Java 如何构建两个Wicket应用程序,java,web-applications,wicket,web.xml,Java,Web Applications,Wicket,Web.xml,这是关于以下链接上的helloworld示例: http://wicket.apache.org/learn/examples/helloworld.html helloworld工作正常,我可以使用url调用应用程序:http://localhost:8080/helloworld/。现在,我想扩展第二个应用程序hellowolrd2的示例,以便在调用http://localhost:8080/helloworld2/使用浏览器,会出现第二个页面helloworld2(类似于hellowor

这是关于以下链接上的helloworld示例:

http://wicket.apache.org/learn/examples/helloworld.html

helloworld工作正常,我可以使用url调用应用程序:
http://localhost:8080/helloworld/
。现在,我想扩展第二个应用程序
hellowolrd2
的示例,以便在调用
http://localhost:8080/helloworld2/
使用浏览器,会出现第二个页面helloworld2(类似于helloworld)。假设我有文件
HelloWorld2.java
HelloWorld2.html
。我应该在文件web.xml中更改什么

您没有两个应用程序,实际上您有两个页面。 第一个(helloworld)由映射为响应为主页,它在helloworld应用程序中定义:

@Override
public Class getHomePage() {
    return HelloWorld.class;
}
如果需要localhost:8080/helloworld2/只需在HelloWorldApplication中的init()方法中创建一个映射

@Override
public void init() {
super.init();
this.mountPage("/helloworld2", Helloworld2.class);
}

你没有两个应用程序,实际上你有两个页面。 第一个(helloworld)由映射为响应为主页,它在helloworld应用程序中定义:

@Override
public Class getHomePage() {
    return HelloWorld.class;
}
如果需要localhost:8080/helloworld2/只需在HelloWorldApplication中的init()方法中创建一个映射

@Override
public void init() {
super.init();
this.mountPage("/helloworld2", Helloworld2.class);
}

您实际上不需要修改
web.xml
中的任何内容。此处定义的唯一相关设置是
元素

<filter-mapping>
    <filter-name>HelloWorldApplication</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
请注意,
helloworld
这里是应用程序的上下文根。因此,除非您想在
getHomePage()
中定义一些逻辑,根据某些条件返回一个或另一个类(不要真的认为这是您想要的),否则它将有效地服务于
HelloWorld

现在,针对您的问题,使用Wicket,您可以使用以下方式将(可书签)页面装载到URL:

这将使
http://localhost:8080/helloworld/
service
HelloWorld
class,作为主页。但也会为它提供请求
http://localhost:8080/helloworld/helloworld
。请求<代码>http://localhost:8080/helloworld/helloworld2将有效地服务于
HelloWorld2


或者,如果您真的想要
http://localhost:8080/helloworld2/
为了服务于
HelloWorld2
,您应该部署另一个webapp,当然它有自己的
web.xml
,并且有上下文根
HelloWorld2

,您实际上不需要修改
web.xml
中的任何内容。此处定义的唯一相关设置是
元素

<filter-mapping>
    <filter-name>HelloWorldApplication</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
请注意,
helloworld
这里是应用程序的上下文根。因此,除非您想在
getHomePage()
中定义一些逻辑,根据某些条件返回一个或另一个类(不要真的认为这是您想要的),否则它将有效地服务于
HelloWorld

现在,针对您的问题,使用Wicket,您可以使用以下方式将(可书签)页面装载到URL:

这将使
http://localhost:8080/helloworld/
service
HelloWorld
class,作为主页。但也会为它提供请求
http://localhost:8080/helloworld/helloworld
。请求<代码>http://localhost:8080/helloworld/helloworld2将有效地服务于
HelloWorld2


或者,如果您真的想要
http://localhost:8080/helloworld2/
要服务于
HelloWorld2
,您应该部署另一个webapp,当然要有自己的
web.xml
,使用context root
helloworld2

可能值得一提的是,实际上
http://localhost:8080/helloworld/helloworld2
将用于此页面,而不是
http://localhost:8080/helloworld2
@XaviLópez,除非将应用程序装入根上下文。(在概念上讨论这一点时,如果不消除应用程序名称和页面名称/安装位置(其中一个可以是应用程序的“索引”)的歧义,这有点令人困惑。)值得一提的是,实际上
http://localhost:8080/helloworld/helloworld2
将用于此页面,不<代码>http://localhost:8080/helloworld2@XaviLópez,除非将应用程序装入根上下文。(在概念上讨论这个问题时,如果不消除应用程序名称和页面名称/安装位置(其中一个可以是应用程序的“索引”)之间的歧义,这有点令人困惑。)当我将mountPage()放在方法init()中时,这很好。如果构造函数中有moutPage(),我不知道为什么它不起作用。感谢您的帮助的确,
mountPage
应该在
init()
上,而不是在构造函数上。我修改了答案。作为答案的旁注,检查一下这个,您可能会发现它很有用。当我将mountPage()放在方法init()中时,它工作得很好。如果构造函数中有moutPage(),我不知道为什么它不起作用。感谢您的帮助的确,
mountPage
应该在
init()
上,而不是在构造函数上。我修改了答案。作为答案的旁注,看看这个,你可能会发现它很有用。