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/
Related
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.
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
So I have let's say an application named MyApplication. I deploy it with a virtual server on glassfish and all is well since I set the default welcome page. Let's say the virtual server is to listen on mydomain.com
I goto mydomain.com and i see my index file of my application just fine. Then i go to do a j_security_check login.
And i am then redirected to: http://mydomain.com/MyApplication/page.xhtml
How can I get this to wehre it is: http://mydomain.com/page.xhtml ?
Now if I do take MyApplication out of the URL and try to manually goto that page it is blank, as I believe it is not being processed by JSF.
What I have tried.
* Setting the default glassfish application to my application and setting the context path of my application to / (glassfish complains and i cannot deploy my application)
* Doing the same as above without setting my context path to / and leaving it as is.
Will deploy but same issue.
My main reason for wanting this, is it seems if someone does get redirected to a path without the application name, the session state appears to be different. And causes some sporadic issues with session collision and values not being passed properly. So I either want to force the URLS to use the ApplicationName all the time, OR force them to not use it for the sake of consistancy.
There should be a way to accomplish this since I dont believe we should always have to have the ApplicationName in the URL.
Please help if you can, what I have found by searching seems to take care of it for the initial request but not when doing redirects using the FacesContext extenralContext redirect.
Unless I am not redirecting properly. I am at a loss here.
Thank you for the help.
IMHO you should consider using asap PrettyFaces
Your application URLs will always be elegantly displayed to your users.
I'm trying to deploy my first servlet to my server. There are, of course, many tutorials online. But most of them are very detailed and complicated, and I only need to deploy a few simply servlets to this server.
I found what I think to be the shortest method of deployment: Deployment on Tomcat Startup. I moved my .WAR file (FirstProject.war) into $CATALINA_BASE/webapps folder, but when trying to access it (ServerIP/FirstProject) I get the "The requested resource is not available." error.
Is there anything I forgot in the process of deployment?
I know that deployOnStartup has to be set to true, but I didn't change anything with the server's hosts, so the current host is localhost. I didn't change its settings, so deployOnStartup should be true (It's said that true is the default).
What am I missing?
You are using easiest way but I don't know what you are missing. Here what I would suggest is run your server and access through localhost:8080 then click manage app then enter username and password then you can deploy your war.
If you have any query post command.
Even i used to face this problem while deploying my first web application on Jboss and Apache ..
Even though your code is working properly with all your servlet mappings and paths using in your content files ...some times they kick back in real time environment ..So we have to know the proper deployment folder structure and accordingly we have to change our paths in the code
what i am concluding is check the below lines of code
Examples, assuming root is http://foo.com/site/
Absolute path, no matter where we are on the site
/foo.html
will refer to http://foo.com/site/foo.html
Relative path, assuming the containing link is located in http://foo.com/site/part1/bar.html
../part2/quux.html
will refer to http://foo.com/site/part2/quux.html
or
part2/blue.html
will refer to http://foo.com/site/part1/part2/blue.html
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.