I have a j2ee app running on GAE. There is that pre-generated index.html, which is called every time I run the server - let's say http://localhost:8080. But I want to write my own front-end using AngularJS. For that, I created the whole project with Yeoman and copied all the files to folder in my j2ee project.
Right now -> I can call manually the AngularJS webapp like this: http://localhost:8080/webapp/app/index.html
But obviously, that is not the way one wants to go. I would like to call it simply on http://localhost:8080. How can I achieve this?
So it took me longer than expected, but here's how I got it working using the welcome file:
Here's my folder structure:
web.xml file:
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>So123</servlet-name>
<servlet-class>so123.So123Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>So123</servlet-name>
<url-pattern>/so123</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>webapp/app/index.html</welcome-file>
</welcome-file-list>
</web-app>
Hope this helps.
https://developers.google.com/appengine/docs/java/config/webxml#The_Welcome_File_List
You can also change the root directory in the appengine-web.xml file. Full documentation here.
<public-root>/app</public-root>
Related
I created a Dynamic Web Project on Eclipse with the name JavaEEWebContent. The file structure of the project looks something like this.
After compiling when I do a "Run on Server", it runs fine.
When I go the link http://localhost:8080/JavaEEWebContent/, it works fine and displays me the homepage(in my case its index.html).
The problem:
When I go to http://localhost:8080 it shows
I know that the landing page for http://localhost:8080 looks something like this :
Any idea why it is not coming for me or what could go wrong?
Also I am using Tomcat 8.5.54.
This is how my web.xml looks like if that helps:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<welcome-file-list>
<welcome-file>index3.html</welcome-file>
<welcome-file>index2.html</welcome-file>
<welcome-file>index2.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>addNumbers</servlet-name>
<servlet-class>com.servlet.addNumbers.AddNumbers</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>addNumbers</servlet-name>
<url-pattern>/addNumbers</url-pattern>
</servlet-mapping>
</web-app>
Please help.
Nothing's wrong. Eclipse is deploying your web application, and only your web application, when it launches Tomcat. What you're expecting to see is a separate web application. You'll find it in the web-app/ROOT folder of your downloaded copy of Tomcat.
I have created simple dynamic web project on eclipse. I am trying to submit the html form and passing the request to servlet. When I click on submit i get this exception:
HTTP Status 500 wrapper can not find servlet class com.tcs.navigator.Servlet.labServlet or a class it depends on
in jsp form actoin tag I had given same action path as per web xml which is :
action = "labServlet"
content of web.xml is :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>To Upload Files for processing</description>
<display-name>labServlet</display-name>
<servlet-name>labServlet</servlet-name>
<servlet-class>com.tcs.navigator.Servlet.labServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>labServlet</servlet-name>
<url-pattern>/labServlet</url-pattern>
</servlet-mapping>
</web-app>
I tried following workarounds:
clean tomcat directory
open/close project
clean projects
restart eclipse
Verifying class path
created new dynamic web project with same code
But still the same exception persist.
all libraries like servlet-api.jar are present in build path.
you have kept capital S in "Servlet.labServlet" . system is getting it as a Class named Servlet. name your servlet starting with caps like "LabServlet" in the code and start all your package name with small letters. so your complete class path should be
com.tcs.navigator.servlets.LabServlet
I don't know how to access the html(fp.html) file under webcontent folder.
Deployed app structure
fp(app name)
|__ fp.html
|__ META-INF
|__ WEB-INF
My web.xml has this configuration
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>fp</display-name>
<servlet>
<servlet-name>FpServlet</servlet-name>
<servlet-class>com.fp.FpServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FpServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>fp.html</welcome-file>
</welcome-file-list>
</web-app>
If I access the file localhost:8080/fp/fp.html like this, It shows 404 error.
But accessing localhost:8080/fp/ working fine.
Kindly help me to overcome this problem.
Remember that Tomcat can host multiple applications. So in general your folder structure would look something like this:
~/<yourtomcatfolder>/webapps/<yourapplication>
You put any HTML files you want to access directly under that folder, which means you can then access the file like this:
http://localhost:8080/yourapplication/fp.html
Obviously the port and everything is configurable, so the above is just an example. You put also any CSS and JS files similarly, and you can have sub-folders.
Then you put your classes (servlets etc.), libraries etc. under the special WEB-INF folder under your application's directory.
~/<yourtomcatfolder>/webapps/<yourapplication>/WEB-INF/classes
~/<yourtomcatfolder>/webapps/<yourapplication>/WEB-INF/lib
Anything under WEB-INF is not accessible from outside (so no one can download your class files and decompile them etc.)
I am trying to deploy my WAR in TOMCAT server, and i am using MAVEN 2. My Project name is
"Jira-Synchronization". My project is a simple Ajax call and returns result to display to the user. I have only one page( that's the scope of my project). This is how i made the Ajax call and web.xml
$.getJSON('/Jira-Synchronization/jirarequest','OK', function(jiraData)
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Jira-Synchronization</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>JiraSyncServlet</servlet-name>
<servlet-class>JiraSyncServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>JiraSyncServlet</servlet-name>
<url-pattern>/jirarequest/*</url-pattern>
</servlet-mapping>
if you notice the ajax call is taking the Project name( first i felt weired why it is doing that and to move on with the project i just kept it that way) and every thing worked fine inside eclipse running tomcat(This is the URL i used when running from eclipse http://localhost:8080/Jira-Synchronization/index.html).
When i tried to build it using maven and deploy in tomcat(out side of eclipse) the War is made using this name "Jira-Synchronization-0.0.1-SNAPSHOT. My URL has changed tohttp://localhost:8080/Jira-Synchronization-0.0.1-SNAPSHOT/index.html and now my Ajax call which have my project name in it is also need to be changed. this is how my pom.xml looks like
How should i configure my web.xml or pom.xml so that the ajax request excludes the project name to it?
What worked for me is in the Pom.xml i added this <finalName>Jira-Synchronization</finalName> under the <build> tag and that was able to output the WAR with the desired name as i like
When I access a jsp page like this on an appengine development server:
localhost:8888/index.jsp/
it's displaying the source code of index.jsp in the browser. if you access without the trailing slash (i.e. index.jsp) then it renders jsp but with the trailing slash (i.e. index.jsp/) it displays the source code
Any idea why is this? and how to fix it?
It seems to happen only in development server and not in production. Production gives a 404 Not Found error, which is fine.
I am using SDK 1.6.4
web.xml:
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>RegisterPage</servlet-name>
<jsp-file>/register.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>RegisterPage</servlet-name>
<url-pattern>/signup</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
==========
so...
index.jsp -> renders page
index.jsp/ -> returns source code
register.jsp/ -> returns source code
register.jsp -> renders jsp
signup/ -> renders register.jsp
signup -> renders register.jsp
so it seems like it's the urls with *.jsp/ that have the issue
You should move all the *.jsp files into the /WEB-INF directory, and update your web.xml.
This way the *.jsp files will not be accessible directly, and the source code will be hidden.
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>RegisterPage</servlet-name>
<jsp-file>/WEB-INF/register.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>RegisterPage</servlet-name>
<url-pattern>/signup</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>IndexPage</servlet-name>
<jsp-file>/WEB-INF/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>IndexPage</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index</welcome-file>
</welcome-file-list>
I have the some problem when i have used "redirect" and apache tomcat 7, because the redirect is not supported in new version of apache. For solve your problem search news in changelog of your version of apache (if you use it) for the tag you used in your page, or publish code of your page to be able to suggest other solutions. May be that you're using deprecated tags. Also, keep in check the file localhost[DATE].log for more details