今天对wicket小研究了一下,同struts比较,的确有其过人之处,它更具有强烈C/S结构的UI色彩,可以将
前台的美工&后台的程序员分工明确,关于更多的比较以及特点,可以参考<Wicket开发指南>,作者已经讲的很详细了。
这里就今天我实践过程中遇到的问题备忘一下.
一、代码结构
例子很简单,就是按照<Wicket开发指南>以及wicket中的demo实现的例子:经典的HelloWorld(在web page输出)
例子在Eclipse中的目录结构如下
├─src
│ └─wicket
│ └─examples
│ └─helloworld
└─web
├─META-INF
└─WEB-INF
├─classes
│ └─wicket
│ └─examples
│ └─helloworld
└─lib
在helloworld包中定义了3个文件
1) HelloWorld.java
2) HelloWorldApplication.java
3) helloWorld.html(注意这里小写的h)
二、web配置
web.xml主要配置如下
<servlet>
<servlet-name>HelloWorldApplication</servlet-name>
<servlet-class>wicket.protocol.http.WicketServlet</servlet-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>wicket.examples.helloworld.HelloWorldApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldApplication</servlet-name>
<url-pattern>/helloworld/*</url-pattern>
</servlet-mapping>
三、运行localhost/mywick/helloworld/
运行后出现如下错误:
WicketMessage: Markup of type 'html' for component 'wicket.examples.helloworld.HelloWorld' not found. Enable debug messages for wicket.util.resource to get a list of all filenames tried:
[Page class = wicket.examples.helloworld.HelloWorld, id = 0]
Root cause:
wicket.markup.MarkupNotFoundException: Markup not found. Component class: wicket.examples.helloworld.HelloWorld Enable debug messages for wicket.util.resource to get a list of all filenames tried
at wicket.markup.MarkupCache.getMarkupStream(MarkupCache.java:117)
at wicket.MarkupContainer.getAssociatedMarkupStream(MarkupContainer.java:827)
at wicket.Page.onRender(Page.java:850)
at wicket.Component.render(Component.java:1526)
at wicket.Page.renderPage(Page.java:408)
at wicket.request.target.component.BookmarkablePageRequestTarget.respond(BookmarkablePageRequestTarget.java:226)
at wicket.request.compound.DefaultResponseStrategy.respond(DefaultResponseStrategy.java:49)
at wicket.request.compound.AbstractCompoundRequestCycleProcessor.respond(AbstractCompoundRequestCycleProcessor.java:66)
at wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:902)
at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:929)
at wicket.RequestCycle.step(RequestCycle.java:1010)
at wicket.RequestCycle.steps(RequestCycle.java:1084)
at wicket.RequestCycle.request(RequestCycle.java:454)
at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:219)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
四、总结
大部分文章提到该错误主要是class和对应的html没有放在同一目录,所以我疑惑了半天,我一直是放在同目录下的
这里给大家也提醒一下,不仅要在同目录,而且命名也是大小写敏感的:
1.java类和html文件一定要放在一个包里(同文件夹下)
2.继承WebPage的类如HelloWorld,则其应对应html应该命名为HelloWorld.html(这个问题很难找)
五、问题
因为还没有深入了解,就目前的理解程度,有些疑问.
1.继承webPage的类命名必须要和html一致,是不是会导致同包目录下文件太多,浏览起来很不方便,没有将其分开的办法?
2.所有的html都要放在WEB-INF/classes下,感觉不太符合web工程啊规则啊.其实本质还是能否将这两个分开的问题 :)