unable to find servlet(.java) files converted from jsp - java

I am using eclipse luna and tomcat version 7. I have written few jsp files and executing them on tomcat easily. I have read that jsps are converted into servlets at run time and you can locate them in tomcat/work/catalina/localhost/project name and further. My project name is quizilla and there exist a folder named quizilla-1.0-SNAPSHOT, but this folder is empty. What is the reason and where can i find those .java files. I have attached the screen shot of the folder as wellAs I am in right directory in search of my java files, but the folder is empty. So what should i do

You are using Tomcat from Eclipse, so the work directory is:
projectworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
or something like that (if you haven't changed the Server configuration via Eclipse).

Add
<%=getClass().getResource(getClass().getSimpleName() + ".class")%>
to one of your JSP pages to detect where Tomcat has generated the servlet.

Related

Uploading app to Web App Engine in IntelliJ

I'm trying to deploy my app to Web App Engine. I have WAE module in web part of my project; there is a path specified in Modules/web/Google App Engine:
/Users/Kamil/IdeaProjects/appengine-java-sdk-1.9.12/
Although when I click on we in general (Modules/web/"Paths" tab), I see following settings:
Output path:
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/classes
The problem is:
When I click "Upload Web App Engine Application" following error appears:
Bad configuration: Could not locate
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
I don't get it why it tries to search in wrong directory, not the one specified in Modules. Please advise.
Edit
I noticed that in Modules/web/"Sources" tab whole folder named "target" is excluded. Maybe that's the problem?
According to the error message
Bad configuration: Could not locate
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
, the deployment code is looking for appengine-web.xml, a crucial config file for your App Engine app. It's looking for that file here:
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
Is it possible that the file
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
could not be located ("Bad configuration: Could not locate ") because the file
/Users/Kamil/IdeaProjects/NameOfMyProject/web/target/web-1.0.0-SNAPSHOT/WEB-INF/appengine-web.xml
does not exist?
The path /Users/Kamil/IdeaProjects/appengine-java-sdk-1.9.12/ is the path to your SDK, not the target folder, and is not related to this issue.
The target file is excluded from "sources" because "sources" is the location of files that are included as source code into the build. The target folder is the opposite of source files - it's the flattened-out WAR archive that is used to deploy your app. The deployment tool you use will pack it up into a .war file and send that to the App Engine data centers.
Finally, the output path folder .../classes is where the compiled .java files that turn into .class files for your app are put.
I think you should look into some tutorials on IntelliJ and App Engine to make sure that your project was created and configured properly.
Good luck!
One you can do that locate build folder in explorer and delete it. After that reopen android studio build it again and run it. Now every thing is fine.

web.xml configuration for JSP

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

Where to put jsp project folder in tomcat for hosting?

I am right now working with JSP and using tomcat Apache for that.what my problem is when i am creating one single JSP page and putting in root directory of tomcat then its working fine.but now i have one project that contains some useful jars and other java classes so how to put that whole project directory in tomcat.
I had put that in web app directory but its giving me error as follows
The requested resource (/dailymotion-cloudkey-java-73f6f35/examples/upload.jsp) is not available.
I am Giving snapshot of my web app folder where i had put this folder name as dailymotion-cloudkey-java-73f6f35
i know that i am doing mistake while putting dailymotion-cloudkey-java-73f6f35 directory in tomcat.
but i am totally new in this so i couldn't find out so can anyone tell me
tree Structure of my project
I think dailymotion-cloudkey-java-73f6f35, does not have WEB-INF folder with web.xml file. Due to which it is not able to locate the resources.
or
You can copy your dailymotion-cloudkey-java-73f6f35 project directory into ROOT folder and then try the same URL.
Put it anywhere, but put a context file for your webapp to TOMCAT_HOME/conf/Catalina/localhost which points to for webapps's directory with the docbase attribute. Read details here.

To get the root path of file in java

I am using eclipse Indigo IDE ..I am developing a jsp application (myProject) using eclipse in which i have a property file (myProject\webcontent\db.properties) for configuring database credentials.
I am trying to access this file from a class (myProject\src\samplePackage\sampleDBConnect.java). I have exported samplePackage.jar into *myProject\webContent\WEB-INF\lib*.
I have a Test.jsp page which calls a method in sampleDBConnect.java.
When i am trying to run this Test.jsp page, the current directory path shows C:\Documents and Settings\username. I have my project in some other drive(E:).
Can someone tell me how to access the properties file....
getClass().getResourceAsStream("db.properties");
This assumes your db.properties is in the same directory "samplePackage".
If you want to keep it in src directory or say resource directory then use
getClass().getClassLoader().getResourceAsStream("db.properties");
Since your java code belongs to the same web project you don't have to create a jar of the same project and place that in the WEB-INF/lib folder
move db.properties to myProject\src dir,
java code:
InputStream input = sampleDBConnect.class.getClassLoader().getResourceAsStream("db.properties");

Java applet error

I am doing a project on applets. I designed the applet using netbeans. After building the project in netbeans, I took the directory "classes" and a .html file from the "build" directory and moved it to another new directory. This .html file includes the applet. The .html file displays the applet correctly, when it is viewed from my desktop.
I uploaded the "classes" folder and the .html file to my free server (host4ufree.com) using FileZilla. If I try to view the webpage online, I get the following error instead of the applet getting displayed:
java.lang.ClassFormatError: Extra bytes at the end of class file
I am using JDk 1.6.0 update 18, and uploaded the file using FileZilla both ASCII and binary format manner. Yet, I am not able to solve the error problem. Does anybody know the solution to this? Is there something wrong in the manner in which I'm trying to add the applet to my webpage?
The question is quite unclear :S Anyway...
I uploaded the "classes" folder and the .html file to my free server
(host4ufree.com) using FileZilla.
If your applet contains more that one class I do not recommend upload the project classes folder itself but wrap your applet classes to jar file before delpoying it.
Report if that helped

Categories