你真的不需要修改web.xml. 定义的唯一相关设置是<filter-mapping>元素
<filter-mapping>
<filter-name>HelloWorldApplication</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
,它将/*对应用程序(其上下文根)发出的所有请求( ETC。)。
在示例中,您HelloWorld在请求时会看到该页面,http://localhost:8080/helloworld/因为HelloWorld是在WebApplication. helloworld是 webapp 的上下文根,因此 Wicket 会自动将您带到定义的页面WebApplication#getHomePage():
@Override
public Class getHomePage() {
return HelloWorld.class;
}
请注意,helloworld这里是应用程序的上下文根。因此,除非您想定义一些逻辑getHomePage()以根据某些标准返回一个类或另一个类(不要真的认为这是您所追求的),否则它将有效地服务于HelloWorld.
现在,解决您的问题,您可以使用 Wicket 将(可添加书签的)页面安装到 URL 的使用WebApplication#mountPage():
public class HelloWorldApplication extends WebApplication {
@Override
protected void init() {
mountPage("/helloworld", HelloWorld.class);
mountPage("/helloworld2", HelloWorld2.class);
}
@Override
public Class getHomePage() {
return HelloWorld.class;
}
}
这将使http://localhost:8080/helloworld/服务HelloWorld类成为主页。但也会为它提供请求http://localhost:8080/helloworld/helloworld。请求http://localhost:8080/helloworld/helloworld2将有效地服务HelloWorld2。
或者,如果你真的想http://localhost:8080/helloworld2/服务HelloWorld2,你应该部署另一个 webapp,当然要使用它自己的web.xml,并使用 context-root helloworld2。