WAR deployment in tomcar - java

I need some advise over here. I have deployed a java based app on tomcat server. Tomcat server is installed on aws cloud. I am using the URL as hostname:portno/WAR file name to run the app and When i try to hit the app on browser it throws an error 404. However, when i add index.html after the URL or any other name with .html extsn like for ex hostname:port/warname/abc.html my app runs fine. Can you please advise why it is not running without index.html.

Answer to your question has got to do something with the accepted answer in this thread
How does Tomcat find the HOME PAGE of my Web App?
Simply put, Under WEB-INF/web.xml a home page has to be defined, if nothing is defined then what ever is defined in TOMCAT_HOME/conf/web.xml file will be considered as home page by tomcat server
so in your case I think you did not define a specific home page in WEB-INF/web.xml, that is why tomcat was searching for index.html page which is as per default configuration but index.html is not available to tomcat, so you were seeing 404 error. As soon as you put index.html file there then everything started to work for you

Related

how to redirect an application to error page when accessing without context root

I am working on Jboss EAP 7 application server. My java application is configured with a context root of '/myapps' in jboss-web.xml file.
My issue here is when I access the application without context-root (till port number) I need to redirect the application to an error page (404 page) which is there in our application ear.
example : here is my app url - http://localhost:8102/myapps/login.
If I try to access the application like below URL it should redirect to a custom error jsp page.
http://localhost:8102/login.
Please let me know.
Thanks

The webpage cannot be found - HTTP 404 JSP page

Experts,
My dynamic web project having 3 JSP page and 3 servlets .. and everthing was working fine till date.
when i executed the same project today, it was showing this below message.
The webpage cannot be found - HTTP 404
I deleted the whole project after trying multiple checks... now in web.xml if i remove the servlets section, its displaying the jsp content. but if i add the servlet back its throwing same page cannot be found :(
no error in project and i dont see any logs in eclipse... can someone please tel me why this is happening?
Appreciate your input. Thanks
Below are a few general suggestions on debugging web apps:
3 and 4 would be the first checks for 404.
Try to start the web app in the debug mode, and place the break point in the servlet method: any hit? (or just put a System.out.println in the Servlet);
Check the structure of the dynamic web project in Eclipse: are the compiled java classes of the servlets in there?
Check the context path (url) of the dynamic web project in eclipse project config: not accidentally changed?
Check the log files of the tomcat (access logs and catalina logs) your dynamic web project is associated with.

Forwarding a request from servlet to .jsp fails when deployed on remote server

I have been stuck with this problem for two days now and I cant find a solution.
I have this project structure as above:
I want to forward a request from Survey(it is a Servlet) to survey.jsp.
Now when I deploy this from IntelliJ on localhost the forward is made with success. Now i take the .war and use the Tomcat Apache manager to deploy it to a dedicated Server.
When i call dedicatedserverip:8080 the index.jsp loads properly as in localhost:8080. But when it comes to forward there are two cases:
When the name of .war file is different from survey.war when the forward happens I get error 404 . (In this case I think that the request is forwarded to dedicatedserverip:8080)
When the name of .war file is survey.war when forward happens it happens to load again index.jsp page. (in this case I think the request is forwarded to dedicatedserverip:8080/survey)
Below is the code I use to forward the request:
req.getRequestDispatcher("/survey.jsp").forward(req, resp);
Now my question is: Is there something done wrong? Or is there something that I must understand that I haven't? How can I fix it and get the needed result as in localhost?
Have you tried forwarding relative instead of absolute?
req.getRequestDispatcher("survey.jsp").forward(req, resp);
Then additionally it should be no problem if you change the name of your war file and with it the ServletContext of the application any more.
Finally, I solved the problem. It had nothing to do with the forward, the problem was in the submit form action. Action was action="/survey". I replaced with ${pageContext.request.contextPath}/survey . And it solved the problem. This explains why the index page was called when .war name was survey.warand error page when it was different.
Thank you for your support.

Still have Eclipse EE 404 on Mac after following advice on this issue

First of all, I am aware that there are other questions regarding Tomcat, Eclipse, and the infamous 404 error. However, none of them manages to resolve the issue. I have spent well over 24 hours on this issue.
To save time, when I configured everything (including Tomcat, and creating a server in Eclipse), I:
• Changed the server location from "workspace metadata" to its correct location by using the "Switch Location" button located in the server's Properties window.
• I chose the "Use Tomcat Installation" option in Server Locations, and saved the choice I made.
In both cases, I restarted the server. If you're curious as to what app I'm currently working on, it's a simple Hello World app, found at: http://theopentutorials.com/examples/java-ee/servlet/how-to-create-a-servlet-with-eclipse-and-tomcat/
• I have included the Java file in the "welcome file" list inside web.xml.
Lastly, out of curiosity, why does the Eclipse browser only go to the project directory, and not the servlet itself? (If I add on the servlet name, then "Hello World" appears).
• Yes, if I enter "http://localhost:8080", the default Tomcat page appears, so no issues there.
Can anyone clue me in, as to why I am still getting 404s after all this, and following advice that has been marked as "Accepted" here at SO, such as the following:
HTTP Status 404 - The requested resource (/) is not available
Thanks in advance for any help, it is greatly appreciated.
The error 404 may occur because of large amount of different reasons. In order to resolve that, you should check your tomcat log file out first. It contains by the path:
%PATH_TO_WORKSPACE%\.metadata\.plugins\org.eclipse.wst.server.core\tmp%SERVER_NUMBER%\
logs
Usually it contains some stacktraces which discribes the problem. If not, then you should check your deployed application out there:
%PATH_TO_WORKSPACE%\.metadata\.plugins\org.eclipse.wst.server.core\
tmp%SERVER_NUMBER%\___YOUR_APP____
It might happen that your application was not deployed correctly by eclipse plugin (happens very often) and you should try this:
Project --> clean
'Right click on your server' --> clean
Or just remove your webapp from the directory I mentioned erlier and redeploy it from scratch.
There is something basic you need to understand regarding using tomcat(or application server for that matter). There is a slight difference between using from Eclipse and using from outside
Using From within Eclipse
What happens here is that Eclipse (by default) uses a copy of your tomcat installation and places it in its metadata workplace. This secondary tomcat is used by Eclipse for all deployments, re-deployments and all. Keep in mind that this is not your original copy of tomcat installation.
The difference in this tomcat installation is that is actually a minimal server, meaning that although it has all the deployment capabilities, it does not have some of the extra features that come with the tomcat installation and one main feature is the tomcat's homepage (the only reason why people out there get the infamous 404 resource not found when they try to run-on-server their application).
Workaround
Although not an issue (nor a bug from the Apache's end), you can still view your application by changing the URL to your application's url, homepage or no homepage ! All you have to do is change the url from http://localhost:8080 to http://localhost:8080/yourApplicationName and voila , the default page of your application will be shown that you mentioned in the welcome-page-list. Keep note that if you didn't specify a default page in your web.xml, you will again wind up with, yet again, the dreaded 404 resource not found page. The reason is that Tomcat has found your application, but it doesn't know what to do at the root context of your application. You can either map your servlet to the root of the application (that way it will always run at http://localhost:8080/yourApplicationName) or you can change the URL to the url-pattern that you mapped with the servlet in the web.xml, it must be something like http://localhost:8080/myApplicationName/myServletMappingPattern

An address of a website deployed using Tomcat and Eclipse

I'm trying to run a website using Tomcat and Eclipse. I created a Dynamic Web Project, I configured web.xml file and I also used Maven. In a directory src/main/webapp I put an index.html file. I also made a simple REST service in the same project. So this REST service is working for me (for example, when I put "http://localhost:8080/RESTfulService/rest/item" in an address bar. But what is the address that I should write to get an access to a website I put in a webapp folder? I thought "http://localhost:8080/RESTfulService/" should be working, but it's not.
From what i understand of your setup, try "http://localhost:8080/index.html". Do you have a context path called 'RESTfulService' setup?
Do you have a context element listed in your server.xml? If so, what does it say?

Categories

Resources