Not Showing Welcome Page JSP - java

I have created dynamic web project in eclipse and added index.jsp file, obviously thats my welcome page.I have added it in web.xml,I am using angular js for front-end interface management.
here is my 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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="false" version="3.0">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>ValidateLogin</display-name>
<servlet-name>ValidateLogin</servlet-name>
<servlet-class>ValidateLogin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ValidateLogin</servlet-name>
<url-pattern>/ValidateLogin</url-pattern>
</servlet-mapping>
</web-app>
now what my issue is When I run the project it is showing loading and not opening any content. but if I added the project url+index.jsp in browser address bar then the page loads successfully. I am using route provider in angular js script and that is as follows
app.js
var myApp = angular.module('myApp', [
'ngRoute',
'appController'
]);
myApp.config(['$routeProvider',function ($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'views/login.jsp',
controller: 'LoginController'
}).
when('/main', {
templateUrl: 'views/Home.jsp',
controller: 'MainController'
}).
otherwise({ redirectTo: '/home' });
}]);
here is my dir structure
what is the issue ? can anyone answer ?

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Add.jsp extension in index
Make sure your index.jsp is outside WEB-INF folder
For accessing the jsp the correct url will
http://localhost:8080/ProjectName/index.jsp
Change the port no as per your server. You need to provide the project url for accessing the jsp. Say you have 4 projects deployed on your server each having index.jsp. How will the container figure out which index.jsp to run if you don't provide the project url.

You have mentioned welcome file without any file extension
<welcome-file>index</welcome-file>
just add valid welcome page with file extension, if may be your file is index.jsp
<welcome-file>index.jsp</welcome-file>
and your $routeProvider configuration doesn't affect your welcome page loading you mentioned in the web.xml. route provider only affect after your angular js loaded...

Make sure the welcome-file property is mentioned like this:
index.jsp
Make sure the index.jsp is present parallel to WEB-INF.
Hope this works.

Related

Java servlets on Tomcat take to 404 error but it works fine on localhost

I have design a webApp with NetBeans IDE. It works fine on localhost, but when I deploy it on my host, trying to access the servlets give me a 404 error.
My servlet dos include the URLpattern and the Name specifications, like this
#WebServlet(name = "FAQ", urlPatterns = {"/faq"})
public class FAQ extends HttpServlet {
The servlet just does a "redirection" to a .jsp
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("/faq.jsp").forward(request, response);
}
If I use the URL www.mysite/faq.jsp it works ok, but it doesn't when I try the servlet www.mysite/faq (even it does on localhost, as I said).
I have checked the .class files are compiled and included on the WEB-INF folder and it doesn't seme to be the problem.
Also I tried to add the web.xml description of the servlet like below, but it doesn't work either.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>FAQ</servlet-name>
<servlet-class>beans.FAQ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FAQ</servlet-name>
<url-pattern>/faq</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
I don't know waht could be my problem and it may be a very stupid thing, but I can't find it.
Thank you all.
SOLVED:
As I said, it should be a simple thing.
The hosting server was configurated on Tomcat 10x and JDK 10, while my project was build on jdk 8 and tomcat 7.
The solution was to ask for the hosting provider and change the server configuration to fit my project.

Remote API JAVA url does not work GAE

I have deployed application into GAE. When i try the url as http://aabbbaaacccc.appspot.com/_ah/remote_api. I am getting 404 Error page. I have added in web.xml file. I have given correct app id. It deploys. After deployment successful, An dialog box appears and displays file not found along with notepad.
<servlet>
<display-name>Remote API Servlet</display-name>
<servlet-name>RemoteApiServlet</servlet-name>
<servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RemoteApiServlet</servlet-name>
<url-pattern>/remote_api</url-pattern>
</servlet-mapping>
I need to deploy my app into server and start a Remote api with an other application and share the entites from an other app.
I am struggling with this issue for past 2 days. Please help me.
U can look at the error dialog box in the following link.
http://i40.tinypic.com/bfgzki.png
Thanks.
Appengine should works fine.. i've listed the all details for basic project setup. please look and find what you missed.
The Servlet Class
App Engine Java applications use the Java Servlet API to interact with the web server.
In the directory src/guestbook/, make a file named GuestbookServlet.java with the following contents:
package guestbook;
import java.io.IOException;
import javax.servlet.http.*;
public class GuestbookServlet extends HttpServlet {
#Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}
The web.xml File
When the web server receives a request, it determines which servlet class to call using a configuration file known as the "web application deployment descriptor." This file is named web.xml, and resides in the war/WEB-INF/ directory in the WAR. WEB-INF/ and web.xml are part of the servlet specification.
In the directory war/WEB-INF/, a file named web.xml has the following contents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
"-//Oracle Corporation//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>guestbook</servlet-name>
<servlet-class>guestbook.GuestbookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>guestbook</servlet-name>
<url-pattern>/guestbook</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
This web.xml file declares a servlet named guestbook, and maps it to the URL path /guestbook.
The appengine-web.xml File
App Engine needs one additional configuration file to figure out how to deploy and run the application. This file is named appengine-web.xml, and resides in WEB-INF/ alongside web.xml.
In the directory war/WEB-INF/, a file named appengine-web.xml has the following contents:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application></application>
<version>1</version>
<threadsafe>true</threadsafe>
</appengine-web-app>
appengine-web.xml is specific to App Engine, and is not part of the servlet standard. You can find XML schema files describing the format of this file in the SDK, in the appengine-java-sdk/docs/ directory. See Configuring an App for more information about this file.
Running the Project
The App Engine SDK includes a web server application you can use to test your application.
select Debug As > Web Application.
Testing the Application
Start the server, then visit the server's URL in your browser. If you're using Eclipse and the Google Eclipse plugin, the server runs using port 8888 by default:
http://localhost:8888/guestbook
If you're using the dev_appserver command to start the server, the default port is 8080:
For details please see following tutorials:
Tutorial 1:
Tutorial 2:
Tutorial 3:

Url Mapping in gwt

My GWT project is not working when im trying to run my [project]_build.xml as ant.
This is my web.xml file :
<servlet>
<servlet-name>gwtTest</servlet-name>
<servlet-class>es.gwt.finalTest.server.TestServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>gwtTest</servlet-name>
<url-pattern>test</url-pattern>
</servlet-mapping>
This is the Remote Service Path found at My Service.java
#RemoteServiceRelativePath("test")
Plus when i remove this : private GreetingServiceAsync messageService = GWT.create(GreetingService.class); from my EntryPoint the error doesnt occur anymore but of course i have no access to my servlet
Maybe the "url-pattern" tag should look more like
<url-pattern>/yourApp/test</url-pattern>

eclipse dynamic web project default start page

I created an eclipse dynamic web project, with home.jsp in the WEB-INF folder
The server I'm using is Tomcat 7.0.35
The name of the project is Pilot_1, and I have a servlet which triggers when the URL-pattern is /home
#WebServlet(description = "Initalizes the table", urlPatterns = { "/home" })
I want to specify the URL so that everytime I press Project > Run > Run on Server, the URL is specifically localhost:8080/Pilot_1/home (triggering both the servlet and the jsp page).
I tried changing the Context Root to only "Pilot_1", which gives the URL "localhost:8080/Pilot_1" and doesn't trigger the servlet
I tried changing the Context Root to "Pilot_1/home", which gives the URL "localhost:8080/Pilot/1/home/" and the extra '/' ensures that the servlet doesn't trigger
I tried changing the Context Root to to "home", which gives the URL "localhost:8080/home/", and again, the extra '/' ensures that the servlet doesn't trigger
I've been playing around with URLs and it seems the only time the servlet gets triggered is when the URL is "localhost:8080/Pilot_1/home"
Is there any workaround to this?
This is my web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>home.jsp</welcome-file>
Don't mess with the Context root. Instead, go to the web.xml file and change the welcome-file-list:
<welcome-file-list>
<!-- note that THIS IS NOT home.jsp, just home (the URL mapping of your servlet) -->
<welcome-file>home</welcome-file>
</welcome-file-list>
By the way, revert any change you have done to the context root of the application.
Refer to this answer for an example.

Java rest webservice display name

I've just started building my own rest webservice and I started off by going through this excellent tutorial: http://www.vogella.com/articles/REST/article.html#first_project
However there is something that I don't quite understand. It has to do with the path to the service.
The path is now this for the hello resource:
http://localhost:8080/de.vogella.jersey.first/rest/hello
This is default from the tutorial.
However i would like to change this to a more convenient link, for example like this:
http://localhost:8080/mywebservice/resources/hello
I change the web.xml to the following as a try to achieve it:
<?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">
<display-name>mywebservice</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>de.vogella.jersey.first</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
I changed the display name and the url-pattern but it has no effect. I cant get to the resource using the path I want it to be, though I can retrieve it from the old path.
Why is that? Does the displayname from the web.xml got nothing to do with this?
You are changing the context name of the Webapp. If you're deploying it in the form of a war (webapp archive), the name of the war would be the context name.
In the example you're following, you're creating a Dynamic Web project with that name. You'll have to rename it suitably.
Same problem here.
I tried to change the "display-name", but it does not affect the service-URL at all.
A change in "url-pattern", though, DID change the URL.
So from the "first REST example" from Vogella, I'd say, the URL is initially built as follows:
http:// your_domain:port/**project-name**/url-pattern/path_from_rest_class
Greetings
Jana
ADDITION: SOLUTION
Meanwhile I found out a way to change this very part of the URL (the "display name"):
You go to the application.xml of your EAR project (folder META-INF)
--> if no xml is there, right-click the node "deployment descriptor" and chose "Generate Deployment Descriptor Stub", it creates application.xml))
For altering the URL-part "display name" you have to change the value in "context root".
(the "web-uri" must not be changed!)
now the URL pattern is as follows:
http:// your_domain:port/**context-root**/url-pattern/path_from_rest_class
So you CAN change the URL the way you like. :-) Hope this helps!
Greetings
Jana
Another way to do this is that you right click on your project and goto WebProject settings from where you can change the Context root same as whatever you want in displayName too and then run project again on server.
This worked for me as issue was only with displayName because works fine when we change it for accessing with new URI.
Thanks

Categories