I am developing a plugin for a software written in .jsp technology on Tomcat Server.
The software house which develops the main software (I am only writing a plugin to manage calendar events for that software), has told me it is better not to modify the web.xml file and other configuration files. In advance, I don't have access (and thus cannot modify) the source code of the web-application. I can only add jsp pages and .jars.
I can put .jsp pages, along with .js or .css files in the WEB-INF folder for the front-end. I can also access the WEB-INF/lib directory to add my .jar files for the back-end library with my backend logic.
I have the following question:
In this scenario, I need to call via jquery.ajax method the functions in my .jar library from my FrontEnd.jsp page. How can I achieve that?
I have supposed to do that:
FrontEnd.jsp (calls jquery.ajax (passing the method to invoke))
--> Backend.jsp (reads the request.getParameter(method) and calls the appropriate method in the BackEndLibrary.jar)
--> --> .jar library (executes the server-side code and gets back the result to the Backend.jsp)
<-- Backend.jsp (gets the response and serializes it as a JSON object)
<--<-- FrontEnd.jsp (gets the JSON object through the jquery.ajax method)
Example:
FrontEnd.jsp
$("#click").click(function () {
event= $("#event").val();
date = $("#date").val();
methodBackEnd = "getEventByDate";
// call the ajax backend jsp passing the BackEnd Method to invoke
$.ajax({
type: "POST",
url: "BackEnd.jsp",
data: "{'event':'" + event + "','date':'" + date + "','methodBackEnd':'" + methodBackEnd + "'}",
contentType: "application/json",
async: false,
success: function (data) {
$("#response").html(data.d);
}
});
});
It calls the BackEnd.jsp
<!-- this is the import of my .jar library -->
<%@page import="com.xyz.eventmanagement.*"%>
switch (request.getParameter("methodBackEnd").toString()){
case "getEventByDate":
// call getEventByDate method in the .jar and return a JSON object to the frontend
break;
case "getEventByDescription":
// call getEventByDescription method in the .jar and return a JSON object to the frontend
break;
default:
// don't call anything
break;
}
In your opinion is that correct? Are there different ways to achieve that? I know it's a bit weird but I cannot modify (for example) the web.xml to change url-patterns. Thank you.