Viewing JSPs with Weblogic JSPServlet - java

We are currently migrating from OC4J to Weblogic. We have an ANT script which builds the EAR file. The ANT also compiles and packs all the .jsp files into a jar. But when I tried to run the application on Weblogic it always returned 404 when trying to access .jsps. So I tried to add a mapping in web.xml for weblogic.servlet.JSPServlet for the URL pattern *.jsp, but I still get 404 when I try to access .jsps.
What could be the problem?
Thanks.

Your EAR file structure needs to be correct.
If you are deplying to WLS, you can deploy either an EAR or WAR seperately, however if you choose EAR file, you must have the the JSP's within the WAR file. You should only need to specify servlet and resource mapping within the web and context xml files.
You must also make sure that you have your .jar files in the library. Otherwise you can run into problems.
Let me know if you need more info.

Related

Loading file from application .ear deployed on weblogic

I'm trying to write code that will load *.html file from application .ear and display it. The structure of my application is:
application
-src
-main
-java
-my.package.few.folders
-Class.java
-webapp
-my.html
I'm new in Java and weblogic so I'm not able to figure it out by myself and all threads I found in internet are mostly the same. File should be accessible using:
Class.class.getClassLoader().getResource("main/webapp/my.html");
The problem is that my application is deployed on weblogic and above code gives me path to a weblogic domain (not my application ear where are *.html files). So using this code I'm always getting null pointer exception because .ear is hidden inside few folders in weblogic domain. I want to avoid giving specified path to .ear in weblogic, because it need to work on different servers and with only managed server name changed it will crash. How can I get straight into my .ear, not through weblogic domain?

Trying to access xml file in tomcat via URL, getting 404 error

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

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

can a deployed war/application be edited?

I have an application/war deployed in server. Now at runtime I want to add an xml document to the war/application. can I do that? if yes, what is the path of an war/application for it to be added.
You have to repackage the WAR, redeploy, and bounce the server. It's not that simple.
You can make that data available without the hassle if you put it in a database and have your application access it there.
in the webapps/WEB-INF folder you can find the xml files
It depends on the servlet container/application server.
If you are using Tomcat, wars are getting unpacked to the webapps directory inside the Tomcat directory.
Move webapps/app directory outside the webapps directory, what will cause an undeploy of app
Put your xml file into the app directory
Move app back to webapps what will cause a deploy

Load Properties or XML in glassfish web service

I've got a basic glassfish web service and I'm trying to load some properties from WEB-INF folder.
However,
Thread.currentThread().getContextClassLoader().getResource("test.properties")
this.getClass().getResource("test.properties");
don't seem to be searching in the right directories. Replacing test.properties with ".", i get the directory
file:/C:/Program%20Files%20(x86)/glassfish-3.1.2/glassfish/domains/domain1/lib/classes/
which is completely empty.
How do i load property files from the java layer in a web service like this?
Put it in WEB-INF/classes and ask for "/test.properties"

Categories