I have a JSP file (/page.jsp) in the root of my application directory. I want to use this class located in / WEB -INF / classes / Helper.class.
I tried using the import status of the JSP page with the class name, but that did not work. How can I reference Helper.class so that I can use it in JSP? I do not want to include the class in the package / JAR.
Well, I did not know this until I looked. JSP Spec (JSP.11.2 JSP) is your friend. You will need to transfer this class from the default package.
JSP 2.0, ( a.k.a. ). , , JDK 1.4 . , , JSP . , JDK 1.4, (. http://java.sun.com/j2se/1.4/compatibility.html#source ). , . , , , TLD
/WEB-INF/classes, , , . - ; JSP:
/WEB-INF/classes
<% Helper helper = new Helper(); // use appropriate constructor %>
. /WEB-INF/classes, /WEB-INF/classes/com/mypackage/Helper.class. JSP:
/WEB-INF/classes/com/mypackage/Helper.class
<% com.mypackage.Helper helper = new com.mypackage.Helper(); // use appropriate constructor %>
CLASSPATH WAR - WEB-INF JAR WEB-INF/lib. Java.
, , . , . JSP, .
, , JSTL. - JSP - .
<%@ page import="com.*" %>.
<%@ page import="com.*" %>
J2EE, . J2EE Sun Certified Container, .
. JSP Directives.
- : <jsp:useBean id="now" class="java.util.Date"/>
<jsp:useBean id="now" class="java.util.Date"/>
the above creates an instance of Date and adds it as a request attribute map key now. Then it is available for use, like any other variable of the request attribute, for example, inside el-expressions, such as ${now.time}, it will print time in milliseconds.
now
${now.time}
So, in your scenario you would do <jsp:useBean id="Helper" class="com.your.company.name.Helper"/>. Make sure Helper does not have a public arg constructor.
<jsp:useBean id="Helper" class="com.your.company.name.Helper"/>
more information here http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html
Source: https://habr.com/ru/post/1719194/More articles:Packaging Problems - objective-cDisplay Django code from a Django template - djangoЕсть ли gcc/Xcode прагма для подавления предупреждений? - gccHow to C # turn a variable name into a property name of an anonymous object? - c #How can I remove while (true) from my loop in Java? - javaМожет ли кто-нибудь объяснить следующий код схемы? - schemeDisabling / node view and other hidden views in Drupal? - drupalFuse file system problem - cCSS div to place an image without interfering with other divs - htmlКак создать ограниченный AppDomain? - .netAll Articles