Reputation: 2497
It is about the helloworld example on the following link:
http://wicket.apache.org/learn/examples/helloworld.html
The helloworld works fine and I can call the application with the url: http://localhost:8080/helloworld/
. now I would like to expand the example for second application hellowolrd2
sothat when I call http://localhost:8080/helloworld2/
with the browser, a second page helloworld2 comes (similar to helloworld). Assumed I have the files HelloWorld2.java
and HelloWorld2.html
.What shall I change in the file web.xml?
Upvotes: 1
Views: 932
Reputation: 27880
You don't really need to modify anything in web.xml
. The only relevant setting defined there is the <filter-mapping>
element
<filter-mapping>
<filter-name>HelloWorldApplication</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
, which maps all requests (/*
) made to the application (its context root) to the Wicket Filter (think of it as a servlet), which will handle all Wicket requests and direct them to the appropriate method (component constructor, event handler method, etc.).
In the example, you see the HelloWorld
page when requesting http://localhost:8080/helloworld/
because HelloWorld
is the home page defined in the WebApplication
. helloworld
is the context root for the webapp, so Wicket automatically takes you to the page defined in WebApplication#getHomePage()
:
@Override
public Class getHomePage() {
return HelloWorld.class;
}
Notice that helloworld
here is the application's context root. So unless you want to define some logic in getHomePage()
to return a class or another depending on some criteria (don't really think this is what you're after), it will effectively serve HelloWorld
.
Now, addressing your question, with Wicket you can mount (bookmarkable) pages to URL's using 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;
}
}
This would make http://localhost:8080/helloworld/
serve HelloWorld
class, being the home page. But would also serve it requesting http://localhost:8080/helloworld/helloworld
. Requesting http://localhost:8080/helloworld/helloworld2
would effectively serve HelloWorld2
.
Or, if you really wanted http://localhost:8080/helloworld2/
to serve HelloWorld2
, you should deploy another webapp, of course with its own web.xml
, and with context-root helloworld2
.
Upvotes: 3
Reputation: 394
You don't have two applications, actually you have two pages. The first (helloworld) was mapped by to respond as home page, it was defined in HelloWorldApplication:
@Override
public Class getHomePage() {
return HelloWorld.class;
}
If you want localhost:8080/helloworld2/ just create a mapping in the init() method in HelloWorldApplication
@Override
public void init() {
super.init();
this.mountPage("/helloworld2", Helloworld2.class);
}
Upvotes: 1