qg_java_17137
qg_java_17137

Reputation: 3569

How to get the java path in JSP?

This is my project structure in IntelliJ IDEA:

I can use below code to get the webapp path, but I don't know how to get the java path.

${pageContext.request.contextPath}

Someone know how to get the path?

Upvotes: 0

Views: 499

Answers (2)

Zubair Nabi
Zubair Nabi

Reputation: 1046

I think you need to know some basic rules. JSP is used from front end, thus is used for client side. Although JSP in turn transforms into executable Java Servlets and itself interacts with server(dynamic pages), but you need to understand that if the JSP has a direct source code linkage, then what security will java provide. Anyone can write the malicious code and interact with the actual source code. Thats why it uses the byte code (compiled code) and have its own directory structure. Hope that helps

Upvotes: 0

AxelH
AxelH

Reputation: 14572

The closest information you can have is the package of a class that you can get with Class.getPackage().

public Package getPackage()

Gets the package for this class. The class loader of this class is used to find the package. If the class was loaded by the bootstrap class loader the set of packages loaded from CLASSPATH is searched to find the package of the class. Null is returned if no package object was created by the class loader of this class. Packages have attributes for versions and specifications only if the information was defined in the manifests that accompany the classes, and if the class loader created the package instance with the attributes from the manifest.

Returns:the package of the class, or null if no package information is available from the archive or codebase.

Of course this won't be the absolute path.

PS : Not sure what you want to do with this but this should be what you want.

Upvotes: 1

Related Questions