I have developed SAPUI5 application and trying to use servlets for implementing some server side functionality. I have taken guidance from this tutorial
I use JQuery ajax call from SAPUI5 controller to Servlet which works fine on my local development environment ( i.e. Eclipse Neon , localhost ).
//Name of servlet is GetUserServlet , mapping defined in web.xml
$.get('GetUserServlet', {
userName : "Hello World"
}, function(responseText) {
alert(responseText);
});
This Ajax call successfully calls servlet (200 status) and Hello World is alerted when I run this from Eclipse on my local machine. Basically I capture in servlet parameter userName value and send back to controller js file
string text = request.getParameter("username");
response.getWriter().write(text );
But when this application is deployed to ABAP server , the Ajax call to servlet throws 404 (not found error) as seen in Network console of Chrome developer tools.
Has anybody deployed SAPUI5 application with servlet functionality on ABAP ?
Is it some path issue ?
Please tell cause of error or hint in direction to solve this issue.
The reason why you are getting 404 is because the servlet is not deployed in SAP Server. You can always connect to any Servlet or REST/Web Service API from a SAP UI5 Application but you will have below things to take care of to be able to access those services:
The service should be deployed properly on a server, if it is a an ODATA or Hana Service then it will be easy to access as it will be in same domain and can be deployed in Gateway or HANA servers.
If the service is deployed on any other server which is in a different domain then you need to update the response headers of your servelt/service to allow Cross Origin access otherwise browser will block it and give Cross Origin not allowed error.
The 3 main response headers that you will need in this case are:
Access-Control-Allow-Origin : This can be either a "*" or comma separated domain names that you want to allow access to.
Access-Control-Allow-Methods : GET,POST etc
Access-Control-Allow-Headers : You can tell which header you want the browser to allow in cross domain service such as Origin, Content-Type, Accept;
You are mixing things up a little. The UI5 app is only a front-end component which, in your case, communicates with a backend JEE application (which contains your servlet). I would assume that you are deploying your servlet + UI5 app locally on e.g. a Tomcat instance (or any other web container). You cannot deploy a Java application to the BSP repository.
The page that you have linked from SCN refers to the old ABAP BSP functionality (which is now obsolete; the BSP repository is simply used to store static files of UI5 applications).
The only way in which you could deploy a JEE application (e.g. a WAR) to an ABAP backend is if the backend is in fact a ABAP+Java Netweaver installation. To be honest, I have never personally seen such a system in use. In this case, you don't even need to use the BSP repository, you can deploy the JEE backend (servlets and what ever else) and the static resources (the UI5 app) inside the JEE "Engine" of the server.
Otherwise, if you have only a plain ABAP system, you have the following possibilities: