HTTP状态404 - hello world wicket

时间:2013-05-11 10:26:02

标签: java eclipse wicket

我正在为wicket示例hello world创建项目,我正在运行应用程序,但显示页面显示HTTP状态404 - 和描述:请求的资源()不可用。

这是我的源代码:HelloWorld.java

package com.wicket.hello;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;

public class HelloWorld extends WebPage {

/**
 * 
 */
private static final long serialVersionUID = 1L;

public HelloWorld(final PageParameters pageParameters) {
    add(new Label("message", "Hello World"));
}
}

这是我的源代码:HelloWorld.html

<html>
<body>
    <span wicket:id="message">Message goes here</span>
</body>
</html>

这是我的源代码:HelloWorldApplication.java

package com.wicket;

import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;

import com.wicket.hello.HelloWorld;

public class HelloWorldApplication extends WebApplication {

    @Override
    public Class<? extends Page> getHomePage() {
        // TODO Auto-generated method stub
        return HelloWorld.class;
    }

}

这是我的来源:web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>WicketApp</display-name>
    <filter>
        <filter-name>HelloWorldApplication</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
          <param-name>applicationClassName</param-name>
          <param-value>com.wicket.HelloWorldApplication</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>HelloWorldApplication</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

这是我的来源:pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>WicketApp</groupId>
    <artifactId>WicketApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket</artifactId>
            <version>1.4.17</version>
        </dependency>

        <!-- slf4j-log4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您可以尝试删除pom.xml的warsourcedirectory部分。

是否有任何理由使用旧的1.4.x而不是6.x版本(强制jdk7对我来说意味着你的目标是更新的系统)?

答案 1 :(得分:0)

在构建内部的pom.xml中添加以下代码,这会将HTML文件添加到您的可部署类文件夹中,您的问题将解决

<resources>
<resource>
    <filtering>false</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
    <filtering>false</filtering>
    <directory>src/main/java</directory>
    <includes>
        <include>**</include>
    </includes>
    <excludes>
        <exclude>**/*.java</exclude>
    </excludes>
</resource>