0

I have a text.class file that is in the same directory in my .jsp file, how can I include it in my jsp file? usually all of the classes should be in the WEB-INF,however I can't put it there.. Usually what I do is:

<%@Test.test" %>

where Test is a folder in the WEB-INF, so how can I do this now?

mtk
  • 13,221
  • 16
  • 72
  • 112
aherlambang
  • 14,290
  • 50
  • 150
  • 253
  • are you sure you do *<%@Test.test" %>* and it usually **works** ? – JoseK Nov 11 '10 at 06:43
  • 2
    Don't do that. [Avoid Java code in JSP.](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files) – BalusC Nov 11 '10 at 11:34

2 Answers2

1
<%@ page import="Test.test" %>  

Provided that Test.test is in your classpath .The better place is to put it is:

WEB-INF/classes/Test/test
jmj
  • 237,923
  • 42
  • 401
  • 438
  • I can't put it at WEB-INF as I said previously... so with that in mind? – aherlambang Nov 11 '10 at 07:19
  • @EquinoX I would recommend you to put there only, other way keep it anywhere but add it in your project's classpath to Test dir. it will resolve it – jmj Nov 11 '10 at 07:29
0

Not really an answer, but a warning you should check. Putting your class files at your JSP folder can lead to security concerns. The servlet container allows HTTP access for everything under the root web application dir (or inside the war file) but the content of the WEB-INF and META-INF folders. These folders are protected by default.

If you put a class at a different location, somebody could access an download it just writing the URL at his browser nav bar:

http://host:port/appContext/Test/test.class

I don't know if your app handles sensitive data, or your class contains code accessing main components of your application, which could be exposed if someone downloads and decompile your code: it is kind of a serious security risk.

Rethink your app structure, an keep your classes under the WEB-INF/classes dir. Or at least, configure your container or your web app to forbid access to *.class resources via HTTP requests.

Tomas Narros
  • 13,390
  • 2
  • 40
  • 56