9

I know there has to be a simple answer to this, but Google's not helping at the moment. I've got a dynamic web project in Eclipse which is using Java/Jersey to run a web service. All my java resources are called in a URI like projectname/test/statistics, etc. for different resources. My hangup is on a relatively simple point:
How do I include an HTML file in this project?
I'm planning to have this file as a sort of 'home page', in order to handle logins, etc. I'd like the URI to be something like projectname/ or projectname/login, but I can't seem to find where I can define the path to reference the HTML file. Is there something I need to add to the HTML itself, or is it a setting in the Eclipse project?

Update:
Soo... I still can't run my html file through eclipse. What I have to do right now is deploy a war to Tomcat without the html, then put the html file in a completely separate folder to run it. This means that I have to type a different context root whenever I call my file.

1
  • By the way, I've already tried adding it to the build path. Unfortunately, it's not that simple. :P Commented Jun 15, 2011 at 19:37

3 Answers 3

13

I solved this problem by changing web.xml from:

<servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>

to

<servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>

And then http://servername/MyWebApp launched index.html correctly.

Sign up to request clarification or add additional context in comments.

1 Comment

man, this answer saved me... two days trying a solution without sucess.
10

If you created your project in Eclipse, you probably have a WebContent folder off of the root of your project. Files placed in there will be served relative to your project's context root.

For example, if your context root is MyWebApp, and you put the file hello.html into the WebContent folder, you can see your file at http://servername/MyWebApp/hello.html.

Your context root can be found/changed by going to the project properties and selecting "Web Project Settings".

11 Comments

Do you have a server defined? Is your project published to the server?
Yep. I'm running on Tomcat 6.0. I've got everything else running from http://localhost:8080/contextroot/otherresources except for this html file...
What happens when you go to the URL of the html file? 404?
Yep. It's as if I just typed asdlghasdgasgasdgdsa after the context root (which I actually did and got the same 404).
Oh, and thanks for actually following up on this. I don't see too many people who do follow up, so I really appreciate it.
|
2

My workaround:
Since I haven't been able to get this working directly in Eclipse, I've been placing my html page manually in the directory where my service is deployed to Tomcat. Placing it in the ROOT folder lets me hit the page at localhost:8080/login.html, and I can deploy it to other folders, say Test, to hit it at localhost:8080/Test/login.html, but due to my security settings (at the moment), I cannot place it in the same folder as the rest of my deployed project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.