This is the first time I have ever tried to set up a web application project on my own and for some reason I can't even get it to work with a hello world setup. I have everything set to default, the JDK1.8 selected for compiling and an Tomcat7 server with a index.html page that has only text in it. I should be able to right click on the projet and Run on Server after adding the project to the server but I keep getting a 404 even with this simple setup. What am I missing?
Web.xml welcome list:
<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>
You cannot access files under WEB-INF folder directly. Container will look for classes in WEB-INF/classes and jsp files under WEB-INF can be included by other JSP, but any browser requesting resources down there will get a 404 response.
You should change index.xhtml path from webapp/WEB-INF/index.html to webapp/index.html for corresponding to your web.xml
Related
I have created an app-engine connected android project. The way this works is when you open your webapp directory there is an index.html, which serves as the home page of the api. What I want is to create a Servlet that will generate that home page for me instead of serving it from this webapp/index.html. I have created my servlet. But I am not sure how to refer to it inside web.xml
I imagine I have to replace
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
If you want to keep it simple you can remove the static index.html altogether and create a servlet mapping like this (in web.xml).
<servlet>
<servlet-name>MyWelcomeServlet<servlet-name>
<servlet-class>domain.package.subpackage.class</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyWelcomeServlet</servlet-name>
<url-pattern>/index.html</url-pattern>
</servlet-mapping>
Note: removing or renaming the static index.html is important since Google's content delivery network will serve static files before routing requests to app engine instances.
I want to develop a application and deploy in WebSphere where the requirement is:
if there are any request like http://appserver1:9080/ - it will reach to a landing jsp page
for example http://appserver1:9080/index.jsp
Is it at all possible to redirect to a page even if I don't mention
the resource name?
If you want to redirect from server's root, this is not about your java code or project configuration, it is about server configuration.
Look here for WebSphere configuration.
For JEE projects, on web.xml, you can define as;
<web-app>
....
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
</welcome-file-list>
</web-app>
So
http://localhost:8080/myproject
will load index.jsp
Source for details
From what you are describing, the redirection can be pretty much handled by servlets mapping. Read here:
https://docs.oracle.com/cd/E13222_01/wls/docs92/webapp/configureservlet.html
You can be able to intercept URL requests and process:
// Servlet definition on your web.xml
<servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>com.servlets.ServletHandler</servlet-class>
</servlet>
// This maps all requests to the above defined servlet for processing:
<servlet-mapping>
<servlet-name>ServletHandler</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I hope this helps
You can define welcome files in web.xml
<web-app>
...
<welcome-file-list>
<welcome-file>index.jsp/welcome-file>
</welcome-file-list>
...
</web-app>
But according to the spec index.html, index.htm and index.jsp are welcome files by default. So you probably don't need to configure anything when the file is called index.jsp.
I have a web app which when run should open http://localhost:8084/info/user/user_login.jsp. I have given in my web.xml
<welcome-file-list>
<welcome-file>/user/user_login.jsp</welcome-file>
</welcome-file-list>
But when running the app it opens as http://localhost:8084/info which is not able to obtain the css,jquery and image files.And I have to manually type /user/user_login.jsp after info to go to the right page.
My jsp is in
info-->user(Folder)-->user_login.jsp
How Can I correct this
Place the user_login.jsp in following folder
WebContent/user/user_login.jsp
and change in web.xml file
<welcome-file-list>
<welcome-file>user/user_login.jsp</welcome-file>
</welcome-file-list>
I am just getting started to learn about Web Apps and deploying them to Tomcat. So I started with a sample web app project - made up of struts, hibernate, etc., etc.
The ANT build was successful. Also, was able to deploy the web app through an xml under Catalina/host. I am able to open the web site with no issues.
This is the structure of my web app
-exploded
-WEB-INF
-classes
-lib
-web.xml
-index.jsp
-welcome.html
My question is
How does Tomcat know which is the first page / starting page / home page that it is supposed to open? Which file is this specified in?
In any web application, there will be a web.xml in the WEB-INF/ folder.
If you dont have one in your web app, as it seems to be the case in your folder structure, the default Tomcat web.xml is under TOMCAT_HOME/conf/web.xml
Either way, the relevant lines of the web.xml are
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
so any file matching this pattern when found will be shown as the home page.
In Tomcat, a web.xml setting within your web app will override the default, if present.
Further Reading
How do I override the default home page loaded by Tomcat?
I already had index.html in the WebContent folder but it was not showing up , finally i added the following piece of code in my projects web.xml and it started showing up
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I am using appengine and seem to be having some problems with url routing
My web.xml
<servlet>
<servlet-name>ViewServlet</servlet-name>
<jsp-file>viewdata.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>ViewServlet</servlet-name>
<url-pattern>/view/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>default.html</welcome-file>
</welcome-file-list>
The redirection works just fine when I test in the local machine. On upload to appengine when I try to navigate to http://myurl/view/ it redirects infinitely to
http://myurl/view/default.html/default.html...
Is this the right way to redirect in web.xml. Am I missing something here. It work fine on the local machine. Just goes into an infinite loop when uploaded onto gae. Any help would be appreciated...
Note that the <jsp-file> must start with a forward slash (/) if the JSP is in the application's root directory.