I'm starting to work on an applet that will replace an existing one. Having never developed an applet before, I thought I'd get going with the popular HelloWorld example. I am able to run it a couple different ways: in the appletviewer, and also in a browser if I put the JAR file containing the HelloWorld class in the same directory as the HTML (i.e. http://localhost:8080/myApp). I also got it to work when I put the JAR in a directory called HelloWorld just below the myApp directory and specified the codebase parameter in the <applet> tag as HelloWorld. But when I try to specify WEB-INF directories such as classes or lib, I get a ClassNotFoundException. What am I doing wrong?
But when I try to specify WEB-INF directories such as classes or lib, I get a ClassNotFoundException. What am I doing wrong?
Those directories are only meant for classes/jars that are used in JSP and servlets (i.e. the stuff the server needs). The resources inside them are available to site visitors. In this sense 'visitor' means a User Agent (i.e. a browser) or a client side plug-in (such as Flash or the JRE).
You can confirm this for yourself by pasting the full URL to the Jar in the web browser address bar and hit 'enter' to browser to it. The server will give a message back to the effect 'forbidden'.
See also the WEB-INF info. page which expands:
WEB-INF is the name of a folder found in Java web applications. It is used to store deployment information such as the web.xml, required library files and compiled class files. It is normally not accessible from web. Any files which you want to put on war but do not want to make to public then web-inf is the place where you can keep those files.
Related
I have a webapp deployed in Tomee+ 1.6.0 (tomcat 7.0). The app runs fine and I can access all pages. Within one of my app's folders (myapp/intructions/) I have placed a xml file that I will access via a client application.
The application will access the file for its configuration, and will be called via a batch file with the following command:
"C:\Java\jre7\bin\java" -cp MyApp.jar com.me.MyApplicationStart "argument1" "argument2"
Within MyApplicationStart the constructor tries to access the configuration from the URL
http://webserver:8080/myapp/instruction/myconfig.xml
As I have no control over the above methodology, this cannot be changed.
I would expect the xml to be downloaded (or fetched) and my application to work fine, but instead I get a 404 error. If I change the extension of my config file to .properties, everything works fine, but someone else other than me in the team insists that we use xml for the config file, since it will allow more automation features.
What gets me is why can't I access this xml (or any other) file from tomcat. It seems that in previous versions of tomcat this was not a problem, or at least not with files outside the WEB-INF folder. Now it is and it seems to be exclusive to xml files, which suggests that there's a configuration in place that prevents access to this extension from anywhere in the webapp.
Would anybody know what this configuration is, or what is the mechanics behind this error?
Thanks in advance.
for security reason, WEB-INF folder is not accessible from client side.
put your xml file in other location.
and try again, It will work
This is the structure of the JSP app on eclipse.Once I run it on eclipse using tomcat server(localhost:8090/index4.html) it works.On the index page i have to add details,this details are uploaded via the servlet as you can see above Java Resources->src->FileUPloadDBServlet(Also I am not sure if it uses this or it uses WEB-INF->src->FileUploadServlet below.)
In my index4.html the action is action=uploadServlet(no address given for it).This everything works on using eclipse.
But once I put the QMS folder(not WAR) from eclipse worskspace to tomcat ROOT,the index4.html works but the following action,i.e uploadServlet doesnt work(here I use the address localhost:8090/WebContent/index4.html)I dont have a web.xml.
Is that creating a problem?
Please provide me help.
You need to put your project folder or .war file in the
webapps folder of Tomcat directly not in ROOT folder under webapps.
Try to follow directory structure as follows
Photo Courtesy http://www.studytonight.com/servlet/steps-to-create-servlet-using-tomcat-server.php (Here you can also find more details on Servlet and JSP, as well as project structure)
Where you have your web.xml put into the WEB-INF folder under your application folder.
For java files you don't need the source files, the classes folder will have all the source folder (src) files compiled and ready to execute.
The lib will contain all the .jar files you need for your application to run.
Make sure you put web.xml file at proper place, because without it, application will not be able to run. Because as they say web.xml is Heart of the application.
Let me explain you the problem.
When we configure a dynamic java project to run on eclipse the server takes the just the stuff from webcontent folder and deploy it the wbcontent folder contains web.xml file which defines the url descriptor for servlet.
now when you copy the whole folder the server can not find the web.xml file which is a descriptor where it expects the file to be.
hope its clear comment for clarification
I have some stuff under src/main/resources path.
Specifically I have a folder with report templates called reports.
I understand that when the application is deployed/run all files and folders under src/main/resources go to the classpath, namely my project's WEB-INF/classes.
This means that a folder WEB-INF/classes/reports will be created in my server.
Now I want to access my reports as paths, not as inputstream, because my reporting code in java supports a filepath and not an inputstream. So I have to be able to get the WEB-INF/classes/reports absolute path (or relative, I don't care as long as it is right).
Reading some answers regarding similar questions, I have already tried the following things:
getClass().getResource(".").getPath(); --> this returns the exact path of the class I am currently at in my classpath, namely: C:\Tools\JBoss Application Server 7.1.1\standalone\deployments\myProject.war\WEB-INF\classes\aaa\bbb\ccc\ddd
getClass().getClassLoader().getResource(".").getPath(); --> this returns: C:\Tools\JBoss Application Server 7.1.1\modules\sun\jdk\main\service-loader-resources, which is completely irrelevant.
I want something to return C:\Tools\JBoss Application Server 7.1.1\standalone\deployments\myProject.war\WEB-INF\classes
If it is not possible, I will get the first path and go as many folders back as needed to reach classes folder.
Thank you.
You need ServletContext.getRealPath(String) method.
getServletContext().getRealPath("/WEB-INF")
I am trying to use an applet that is located in a jar that is located somewhere else in my system (not in the same project location as the web stuff). I know of a property called codebase which is pointing to where the web for look for the jar that has the applet class. This is the code that I put in, but can't get it to work...
<script type="text/javascript">
if (_app == "Netscape")
{
document.write('<object classid="java:UareUApplet.class"',
'type="application/x-java-applet"',
'name="UareUApplet"',
'width="1"',
'height="0"',
'type="application/x-java-applet"',
'pluginspage="http://java.sun.com/javase/downloads"',
'archive="UareUApplet.jar, dpuareu.jar"',
'onFMDAcquiredScript="onFMDHandler"',
'onEnrollmentFailureScript="onEnrollmentFailureHandler"',
'onImageCapturedScript="onCaptureHandler"',
'codebase="C:\Users\modonnell\Desktop\UareUApplet\UareUApplet\UareUApplet\Register\"',
'onDisconnectedScript="onDisconnectedHandler"',
'onConnectedScript="onConnectedHandler"',
'onErrorScript="onErrorHandler"',
'onLoadScript="onLoadHandler"',
'bRegistrationMode="true"',
'bDebug="true"',
'bExclusivePriority="true"',
'scriptable="true"',
'mayscript="true"',
'separate_jvm="true"> </object>');
}
If I paste in the jar into the folder of my web project, and take away the "codebase" declaration, the applet will work. But I don't want to have to paste in the jar after each compile.
I needed to add the path to the jar all in the archive tag. I needed to completely remove the codebase tag.
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?
<%# 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
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.