“资源”如何获得?上下文路径在 Wicket 中协同工作 + Tomcat安装
我是一名服务器端 Java 程序员,试图学习 Web 开发,并一直在尝试 Wicket、CSS、Tomcat、MySQL 和 Web 开发。使用 Maven 进行 Hibernate 构建。我遇到了未找到 CSS 文件的问题,但我不确定是 Wicket 还是 Tomcat,甚至可能是我的托管提供商导致了问题。设置如下:
LoginPage.html 页面的 HTML 包含以下内容:
<head>
<title wicket:id="pageTitle"></title>
<link wicket:id="stylesheet"/>
</head>
这将在相应的 LoginPage.java 代码中填充:
public LoginPage(final PageParameters parameters)
{
// Setup page
add(new StyleSheetReference("stylesheet",
AppUserPage.class, "default.css"));
我使用“mvn package”创建一个“.war”文件。一旦我将此 .war 文件部署到我的托管网站,HTML 文件就可以通过 Wicket 加载但没有应用 CSS。
如果我使用“查看源代码”,我会看到以下内容:
<head>
<title wicket:id="pageTitle">HR-Box Login</title>
<link wicket:id="stylesheet" rel="stylesheet" type="text/css"
href="resources/ca.svarb.hrbox.web.appuser.AppUserPage/default.css"/>
</head>
我认为关键是现在在 deafult.css 文件的 href 中添加了一个“资源”路径。奇怪的是,如果我将 .war 文件部署到本地默认 Tomcat6 安装或使用“mvn jetty:run”运行,这两个工作正常 - 我可以加载“http://localhost:8080/mywebapp-1.0- SNAPSHOT/?wicket:bookmarkablePage=:ca.svarb.hrbox.web.login.LoginPage" 并且它使用 CSS 文件渲染得很好。
我的问题:
- 如何添加这个“资源”路径?我在 Wicket 配置中找不到任何告诉它将此添加到路径中的内容。
- 做默认的Tomcat6& Jetty 安装有一些东西可以让他们了解在“资源”路径上哪里可以找到文件?我的托管提供商正在使用 Tomcat,但也许他们更改了默认配置以不自动映射此路径。
如果有帮助,该应用程序的源代码位于 sourceforge 上:
https://wicket-hr-box.svn.sourceforge.net/svnroot/wicket-hr-box/branches/mysql
从 SVN 签出并使用“mvn jetty:run”应该构建并运行应用程序,CSS 工作正常。
实时站点在这里:
I am a server side Java programmer trying to learn web development and have been experimenting with Wicket, CSS, Tomcat, MySQL & Hibernate with Maven for the build. I'm having an issue with the CSS file not being found, but I'm not sure if it is Wicket or Tomcat or maybe even my hosting provider causing the problem. Here's the setup:
The HTML for the page LoginPage.html contains the following:
<head>
<title wicket:id="pageTitle"></title>
<link wicket:id="stylesheet"/>
</head>
This gets filled in the corresponding LoginPage.java code with:
public LoginPage(final PageParameters parameters)
{
// Setup page
add(new StyleSheetReference("stylesheet",
AppUserPage.class, "default.css"));
I use "mvn package" to create a ".war" file. Once I deploy this .war file to my hosted web site, the HTML file loads through Wicket just fine but with no CSS applied.
If I use "view source" I see the following:
<head>
<title wicket:id="pageTitle">HR-Box Login</title>
<link wicket:id="stylesheet" rel="stylesheet" type="text/css"
href="resources/ca.svarb.hrbox.web.appuser.AppUserPage/default.css"/>
</head>
I think the key is that there is now a "resources" path added in the href to the deafult.css file. The weird thing is if I deploy the .war file to a local default Tomcat6 installation or use "mvn jetty:run" to run, both of these work fine - I can load "http://localhost:8080/mywebapp-1.0-SNAPSHOT/?wicket:bookmarkablePage=:ca.svarb.hrbox.web.login.LoginPage" and it renders using the CSS file just fine.
My questions:
- How does this "resources" path get added? I can't find anything in Wicket configuration that tells it to add this to the path.
- Do the default Tomcat6 & Jetty installations have something which make them understand where to find files on the "resources" path? My hosting provider is using Tomcat, but maybe they changed the default configuration to not automatically map this path.
If it helps, the source for the application is on sourceforge here:
https://wicket-hr-box.svn.sourceforge.net/svnroot/wicket-hr-box/branches/mysql
Checking out from SVN here and using "mvn jetty:run" should build and run the app with CSS working fine.
And the live site is here:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“resources”是Wicket 中的特殊路径。这样 Wicket 就知道它必须使用特殊的 RequestTarget 来处理此资源请求。
"resources" is a special path in Wicket. This way Wicket knows it has to use a special RequestTarget to process this resource request.