The webpage cannot be found - HTTP 404 JSP page - java

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.

Related

WAR deployment in tomcar

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

How to Configure Subdomains to Work For Java Servlets?

Not managed to find an answer to this anywhere yet, I'm getting close to having this implemented, just one final hurdle that I've not managed to crack.
Single server. Split up using WHM into individual cPanel accounts. 1 instance of Tomcat 7 running. Servlet class files and JSP files deployed.
www.first-website.com - All works perfectly.
www.second-website.com - www. points to another server completely (non-Apache Tomcat / Java), so please ignore that part
sub-domain.second-website.com - Manages to load main Welcome File correctly which is being processed as a Servlet. I'm getting a 404 error though when I try and access sub-domain.second-website.com/about-us/ for example, for all of the sub-directory pages (i.e. url-patterns from web.xml) - this all works on my local machine, so this is something that I've missed configuring the server. The 404 page that it is showing is a server level 404 page, not an Apache Tomcat 404 page which leads me to believe this is an issue somehow related to all of this, http://tomcat.apache.org/tomcat-7.0-doc/virtual-hosting-howto.html - which I'm struggling to understand what this page is actually talking about.
Pointers?
Short answer to the specific problem above, add the following to your .htaccess file within your document root for the sub-domain;
RewriteEngine on
SetHandler jakarta-servlet
SetEnv JK_WORKER_NAME ajp13
Long answer, this is how to do it all, https://www.contradodigital.com/2017/05/24/how-to-install-servlet-support-on-a-subdomain-on-apache-tomcat-7-using-command-line-cpanel-and-whm/

can't start my first app on struts2

I'm new in java web apps. Do this example: http://www.tutorialspoint.com/struts_2/struts_examples.htm
But can't start it in browser. Tomcat is properly working and shows me it's start page for localhost:8080. When I do
localhost:8080/HelloWorldStruts2/index.jsp
request as it shown in the example I see only :
HTTP Status 404 - /HelloWorldStruts2/index.jsp
type Status report
message /HelloWorldStruts2/index.jsp
description The requested resource is not available.
Apache Tomcat/8.0.20
Please help to solve the problem.
Did it deploy the HelloWorldStruts2 module properly?
I suggest you check Tomcat logs (located in tomcat home -> logs) to see if an exception happened while deploying the Struts app.

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

how to make my files present in a tomcat server to the browser

I have installed Tomcat 5.0 in order to execute a web application. How can I show my files which are present in Tomcat to the web browser? I tried http://hostname:8080/myfolder/login.html, but I can't see the files.
One more thing I know about JDBC and other database connectivity and I have developed a HTML page. How can I let a button in the page execute the code written in a Servlet and perform validations?
The simplest thing is to add to the root webapp. That is webapps/ROOT. Any file you put in there will be served unless you change the default configuration.
You should read about the details, of course.
I have installed Tomcat 5.0 in order to execute a web application.
First of all, why are you using the ancient (8 year old) Tomcat 5.0? If you can, rather grab the latest one, Tomcat 6.0.
How can I show my files which are present in Tomcat to the web browser? I tried http://hostname:8080/myfolder/login.html, but I can't see the files.
Is myfolder the context name or just a folder in your webcontent? If it's a context name, then you need to ensure that it's properly deployed. You can find details in the server logs in the /logs folder. If it is a folder in your webcontent and the webapplication is thus supposedly to be the "root" application, then you need to ensure that it's deployed as ROOT.
To learn more about using Tomcat, go through the documentation.
One more thing I know about JDBC and other database connectivity and I have developed a HTML page. How can I let a button in the page execute the code written in a Servlet and perform validations?
To the point, just create a class which extends HttpServlet, implement the doPost() method, define the servlet in web.xml and let the action attribute of the HTML <form> element point to an URL which is covered by the url-pattern of the servlet mapping in the web.xml.
As the question is pretty broad, I have the impression that you haven't learned in any way how to work with Tomcat and JSP/Servlets. I would strongly recommend to go through those tutorials to familarize yourself with JSP/Servlet on Tomcat and Eclipse (an IDE) first: Beginning and Intermediate-Level Servlet, JSP, and JDBC Tutorials
Tomcat is not a web server like, say, Apache. It's a servlet container. You can not just move file in a subfolder which seem to be what you did. You need to pack your web application in a .war and deploy it.
The URL should rather be http://host:8080/webapp/subfolder/login.jsp
Without much information it's hard to help. Please edit your question and describe what you've done so far.

Categories

Resources