0

I recently got some files from a vendor and the code is inform of an eclipse project. I opened the project in eclipse and the code executes expected. This is project screenshot:

enter image description here

I now want to use the project in my jsp web page. Basically i want to receive post values from my users using the url http://localhost:8080/post.jsp

In the eclipse project, this is where my code is getting executed and getting the response

package pdslipay;

public class ATestClass {

     public static void main(String[] args) {

         RequestsManager req = new RequestsManager();

         try {
            req.payBillPrePaid("88559966", "0", "OZONE", "00001");
        } catch (Exception e) {
            e.printStackTrace();
        }

     }
}

I want to integrate the code above and be able to call

<%
 RequestsManager req = new RequestsManager();
 out.println("Get Response " + req.payBillPrePaid("88559966", "0", "OZONE", "00001"));
%>

How do i use my eclipse code in jsp keeping in mind that my main class utlises package pdslipay;

P.s - I have not done something like this before and i am not a java expert.

Thanks.

  • You need to package your class and jsp into .war and deploy into a web-container e.g. Tomcat or Jetty. I suggest you read up on how to design a web application: http://www.journaldev.com/1854/java-web-application-tutorial-for-beginners – Minh Kieu May 23 '17 at 18:05
  • I have skimmed through the page and i shall need to go into it in detail. A little more explanation would do. –  May 23 '17 at 18:21

1 Answers1

0

From the question, I'm assuming that you are doing a web application project using java servlets. You can import the class "RequestsManager" to jsp page by adding the following import directive in your jsp page :

<%@ page import="pdslipay.RequestsManager" %>
<%
 RequestsManager req = new RequestsManager();
 out.println("Get Response " + req.payBillPrePaid("88559966", "0", "OZONE", "00001"));
%>
arjun
  • 1,645
  • 1
  • 19
  • 19
  • I am only using jsp and i was wondering whats need to be done to have the eclipse code usable in jsp. –  May 23 '17 at 18:19
  • When a jsp page is requested by client(browser) to the server, the server compiles the jsp(also present at server) and sends back the response to client. Servlet acts as an interface between client and server. And where are the servlets present in your case. The class files you mentioned in your question should be placed in the same location. Please refer https://stackoverflow.com/questions/20373223/how-to-run-a-jsp-program for a better understanding. – arjun May 23 '17 at 18:30
  • Wow, in my mind, running jsp files was as simple as placing the java files inside webapps root and running the file i.e `post.jsp` Infact post.jsp does exist and i am able to display date using `

    Today's date: <%= (new java.util.Date()).toLocaleString()%>

    `
    –  May 23 '17 at 18:36