Pass JSP variable to a java class method

I have a JSP file named as project.jsp. It contains a variable

String context = request.getcontextpath();

which will deliver context path of my server URL.

/ARUBA-LIB-G3245-KITKAT from http://localhost:8080/ARUBA-LIB-G3245-KITKAT/.

Now I want to access this context variable from my project.jsp file to java class which is in jar format file and resides in WEB-INF/lib/AuthenticateDetails.jar.

How can I access this variable from specified java class file?

Upvotes: 0

Views: 948

Answers (2)

Joop Eggen
Joop Eggen

Reputation: 109547

The same as in java, an import statement and so on.

<%@ page import="java.util.Random"
         import="org.authdetails.dao.SomeClass" %>

(Or many imports in one import=... with line break in string.

<%  new SomeClass(contextPath); %>

Using the MVC (Model-View-Controller) principle, one normally has a servlet (Controller, compilable!) that prepares the data (Model) and puts the data as request attributes, and then forwards to the JSP (view).

In the JSP you can use EL (Expression Language) variables, where some are predefined to access session variables, request parameters and such.

Combining that with JSP tags, one rarely needs to use <% ... %> scriptlets.

Upvotes: 1

vreddy
vreddy

Reputation: 173

Pass the context path variable to the processing method in the library class (library class should be accessible from the jsp though import directive)

Upvotes: 0

Related Questions