Simple servlet code
Forum wellwishers giv some simple easy to understand Servlet Codes for JServlet beginners an especially me with the code explanation.
Tks
MichelFdO M
Start reading part II of the Java EE tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/bnadp.html
Servlets are covered in chapter 4 and on.
Similar Messages
-
Problem With Deploying a very simple Servlet
HELP REQUIRED:
Hi,
I'm including code of a very simple Servlet application (I shd not call it an application):
index.html
==========
<html><body bgcolor="#FFFFFF">
<head>
<title> Rajeev Asthana </title>
<form action = "/HelloWorldApp/HelloWorld" method = "POST" >
Please press Submit
<input type = "submit" value = "Press Me!">
</form>
</body></html>
HelloWorld.java
===============
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body bgcolor=\"#FFFFFF\">");
out.println("<p>Hello World!</p>");
out.println("</body></html>");
out.close();
web.xml
========
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>HelloWorldApp</display-name>
<servlet>
<display-name>HelloWorld</display-name>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
</web-app>
sun-web.xml
===========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.0 Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-0.dtd">
<sun-web-app xmlns="http://java.sun.com/xml/ns/j2ee">
<context-root>/HelloWorldApp</context-root>
<session-config>
<session-manager persistence-type="memory">
<manager-properties/>
<store-properties/>
</session-manager>
<session-properties/>
<cookie-properties/>
</session-config>
<cache enabled="false" max-entries="4096" timeout-in-seconds="30">
<default-helper/>
</cache>
<class-loader delegate="true"/>
<jsp-config/>
</sun-web-app>
I have deployed it in following directory structure:
C:\Sun\AppServer\domains\domain1\applications\j2ee-modules\HelloWorldApp\
|
|
| | | |
| | | |
META-INF WEB-INF HelloWorld.java index.html
|
|
| | | |
| | | |
classes sun-web.xml web.xml sun-j2ee-ri-project
|
|
HelloWorld.class
While generating HelloWorldApp.war (which is the war file for this app), I specifies /HelloWorldApp as context root (sun specific).
Now, when I deployed it thru Admin Tool and then clicked on "Launch", it displays a page with :
Please press Submit Press Me!
But when I click the button "Press Me!", it says:
"The requested resource (/HelloWorldApp/HelloWorld) is not available."
What should I do to correct the problem?
Thanks in advance.
Yes, you need to add a servlet -mapping element and adjust your form to submit to the appropriate URL mapping.
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/servlet/Hello</url-pattern>
</servlet-mapping> -
Weblogic error while deplying a simple servlet program
Hi This is a very simple servlet program.
I am trying to deploy it on the weblogic server but i get this error as follow
Unable to access the selected application.
*javax.enterprise.deploy.spi.exceptions.InvalidModuleException: [J2EE Deployment SPI:260105]Failed to create*
DDBeanRoot for application, 'E:\AqanTech\WebApp1\myApp.war'.
I have checked everything, right from my code to my web.xml file. I have used a build.bat file to build my war file.
PLEASE HELP ME TO SOLVE THIS HUGE PROBLEM OF MINE ?
Thanks,
ShoebHi,
The J2EE Error code siply suggest that there is something wrong in your Deployment Descriptors...
Can u please post the XML files available inside your "WEB-INF" directory?
Thanks
Jay SenSharma
http://jaysensharma.wordpress.com (WebLogic Wonders Are Here) -
How to Run a simple servlet "HelloWorld.java" in JBoss 3.0 ?
Dear all,
I am a beginner and I want to run a simple "HelloWorld.java" servlet .
I need to use JBoss 3.0 .
After I run this simple servlet, I need to use EJB-Servlet-JSP to implement MVC .
I have the servlet code and I am able to compile it.
But I dont know how to proceed as to where to put the class files , where do I specify an alias for my servlet and what modifications I need in Web.xml,Jboss.xml,Application.xml ?
I do not anything about tools like Ant or Xdoclet so need to proceed without them.Please alos let me know where I can fond complete info about Ant and Xdoclet .
Thanx in Advance,
SujithI am not sure of the JBoss package that you are using. If you are using the JBoss-Tomcat package, here's the solution. Create either a .war file or create a directory with the name <your-webapp>.war under <jboss-root>/server/default/deploy. If you are creating a war file, you have to place that war file in the same directory. JBoss-Tomcat will keep looking at this directory for new files or updates to files and deploys/re-deploys as required.
The contents of the war file should be something like this.
WEB-INF - directory
WEB-INF/classes - your servlet classes
WEB-INF.web.xml - your configuration. Here you can specify the servlet name, class and URI mapping.
Now, you can call your servlet using the browser in this way: http://localhost:8080/<your-webapp>/servlet/<servlet-alias>. Here the <your-webapp> is the prefix of the .war file.
Resources:
Ant - http://jakarta.apache.org/ant/
Xdoclet - http://xdoclet.sourceforge.net/ -
What's wrong with my servlet code ?
<p>
Hi,
</p>
<p>
I need to redirect user from jsf application to PHP app with some request attributes using POST method. To check how to do at first I prepared simple servlet:
</p>
<p>
public class TestServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,
</p>
<p>
IOException {
req.setAttribute("p1","Value One");
req.setAttribute("p2","Value Two");
res.sendRedirect("http://www.mycompany.pl/test.php");
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException,
</p>
<p>
ServletException{
doPost(request,response);
</p>
<p>
I also prepared simple PHP page to display these attributes (Im sure this page works correct):
</p>
<p>
<html>
<body>
Attribute p1: <? echo $_POST["p1"]; ?> <br />
Attribute p2: <? echo $_POST["p2"]; ?> <br />
</body>
</html>
</p>
<p>
Te problem is that attributes from servet don't displayed on PHP page - why. What is wrong wit this servlet ?
</p>
<p>
Kuba
</p>Well if this line of code works for you:
res.sendRedirect("http://www.mycompany.pl/test.php");
you could append parameters by building the url string dynamically.
res.sendRedirect("http://www.mycompany.pl/test.php?p1=ValueOne&p2=ValueTwo");
Isn't PHP a server technology, if yes why don't you do all the work in php (you'll avoid cookie problems)?
Regards
Fred
PS I don't think this forum is the right place for php questions. -
PLEASE HELP:not able to load a simple servlet
Hi,
I'm new to weblogic server.I'm trying to setup weblogic 510.Everything was
going fine until I got stuck to this small thing.I'm not able to load a
simple servlet!.
I would appreciate any pointers regarding this.Please Help me!!!
Here is what I tried:
I have installed weblogic510 plug-in for IIS.I could successfully run jsp
files.However I am not able to load simple servlets;It gave an exception
"java.lang.IllegalAccessError: try to access class
weblogic/utils/classloaders/FileSource from class
weblogic/servlet/internal/WarClassFinder"
Details of my configuration:
WebServer - IIS 4.0
IIS port=80
Weblogic port=7001
I had set it in such a way that all the requests first go to IIS and then
IIS redirects them to Weblogic.I've followed the steps according to the
document "Installing the Weblogic ISAPI Plug-in".
I've registered the servlet in weblogic.properties as following:
weblogic.httpd.register.hello=examples.servlets.HelloWorld2
I tested the servlet by URL http://localhost:7001/hello
Following is the eact text for the exception I got in the WeblogicServer
window:
Mon Jul 24 12:13:13 PDT 2000:<E> <ServletContext-General> Error loading
servlet:
examples.servlets.HelloWorld2
java.lang.IllegalAccessError: try to access class
weblogic/utils/classloaders/Fi
leSource from class weblogic/servlet/internal/WarClassFinder
at
weblogic.servlet.internal.WarClassFinder.getSource(WarClassFinder.jav
a, Compiled Code)
at
weblogic.servlet.internal.WarClassFinder.getClassSource(WarClassFinde
r.java:110)
at
weblogic.utils.classloaders.GenericClassLoader.findLocalClass(Generic
ClassLoader.java:381)
at
weblogic.utils.classloaders.GenericClassLoader.reallyLoadClass(Generi
cClassLoader.java, Compiled Code)
at
weblogic.utils.classloaders.RecursiveReloadOnModifyClassLoader$Slave.
loadClass(RecursiveReloadOnModifyClassLoader.java:234)
at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClass
Loader.java:146)
at
weblogic.utils.classloaders.RecursiveReloadOnModifyClassLoader.findLo
calClass(RecursiveReloadOnModifyClassLoader.java:109)
at
weblogic.utils.classloaders.GenericClassLoader.reallyLoadClass(Generi
cClassLoader.java, Compiled Code)
at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClass
Loader.java:172)
at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClass
Loader.java:146)
at
weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubI
mpl.java:291)
at
weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.
java:164)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:99)
at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:742)
at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:686)
at
weblogic.servlet.internal.ServletContextManager.invokeServlet(Servlet
ContextManager.java:247)
at
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.jav
a:361)
at
weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled
Code)
Mon Jul 24 12:13:13 PDT 2000:<E> <ServletContext-General> Servlet failed
with Ex
ception
I dont think there were any problems in the classpath or
servletpath;Basically WeblogicServer was able to locate the servlet but when
it tried to load the servlet it gave this exception.
I would appreciate any ideas/suggestions.
Thanks,
SravanNice to hear it works!
However, one mistake you have in the configuration you provided:
You put D:\weblogic\BDL\servletclasses in both CLASSPATH and
weblogic.class.path, remove it from CLASSPATH.
Cheers - Wei
Sravan Thella <[email protected]> wrote in message
news:[email protected]...
Hi Michael and Wei,
Thank you very much for the response.
My servlet details:
Name - HelloWorld2.class
package - examples.servlets
Location - d:\weblogic\BDL\servletclasses ---- here BDL is my new folder
where I want to keep my servlets
My CLASSPATH(environment) settings:
D:\weblogic\BDL\servletclasses;d:\weblogic\classes\boot;d:\weblogic\eval\clo
>
udscape\lib\cloudscape.jar;d:\weblogic\lib\poolorb.jar;D:\java\jre\lib\rt.ja
r;
my weblogic classpath settings(set it thru wlconfig)
D:\weblogic\BDL\servletclasses;d:\weblogic\classes\boot;d:\weblogic\eval\clo
>
udscape\lib\cloudscape.jar;d:\weblogic\lib\poolorb.jar;D:\java\jre\lib\rt.ja
r;
My weblogic.policy:
grant codeBase "file:d:/weblogic/-" {
permission java.io.FilePermission "d:${/}weblogic${/}-",
"read,write,delete,execute";
permission java.net.SocketPermission "localhost:1-9000",
"connect,accept,listen,resolve";
permission java.awt.AWTPermission "accessClipboard";
permission java.awt.AWTPermission "accessEventQueue";
permission java.awt.AWTPermission "showWindowWithoutWarningBanner";
permission java.io.SerializablePermission"enableSubclassImplementation";
permission java.io.SerializablePermission "enableSubstitution";
permission java.lang.RuntimePermission "accessClassInPackage.*";
permission java.lang.RuntimePermission "accessDeclaredMembers.*";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "createSecurityManager";
permission java.lang.RuntimePermission "defineClassInPackage.*";
permission java.lang.RuntimePermission "exitVM";
permission java.lang.RuntimePermission "getClassLoader";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "getProtectionDomain";
permission java.lang.RuntimePermission "loadLibrary.*";
permission java.lang.RuntimePermission "modifyThread";
permission java.lang.RuntimePermission "modifyThreadGroup";
permission java.lang.RuntimePermission "readFileDescriptor";
permission java.lang.RuntimePermission "setContextClassLoader";
permission java.lang.RuntimePermission "setFactory";
permission java.lang.RuntimePermission "setIO";
permission java.lang.RuntimePermission "setProtectionDomain";
permission java.lang.RuntimePermission "setSecurityManager";
permission java.lang.RuntimePermission "writeFileDescriptor";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission java.net.NetPermission "requestPasswordAuthentication";
permission java.net.NetPermission "setDefaultAuthenticator";
permission java.security.SecurityPermission "getPolicy";
permission java.security.SecurityPermission "setPolicy";
permission java.util.PropertyPermission "*", "read,write";
grant codeBase "file:d:/weblogic/BDL/servletclasses/-" {
permission java.io.FilePermission
"d:${/}weblogic${/}BDL{/}servletclasses{/}-", "read,write,delete,execute";
permission java.net.SocketPermission "localhost:1-9000",
"connect,accept,listen,resolve";
permission java.awt.AWTPermission "accessClipboard";
permission java.awt.AWTPermission "accessEventQueue";
permission java.awt.AWTPermission "showWindowWithoutWarningBanner";
permission java.io.SerializablePermission"enableSubclassImplementation";
permission java.io.SerializablePermission "enableSubstitution";
permission java.lang.RuntimePermission "accessClassInPackage.*";
permission java.lang.RuntimePermission "accessDeclaredMembers.*";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "createSecurityManager";
permission java.lang.RuntimePermission "defineClassInPackage.*";
permission java.lang.RuntimePermission "exitVM";
permission java.lang.RuntimePermission "getClassLoader";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "getProtectionDomain";
permission java.lang.RuntimePermission "loadLibrary.*";
permission java.lang.RuntimePermission "modifyThread";
permission java.lang.RuntimePermission "modifyThreadGroup";
permission java.lang.RuntimePermission "readFileDescriptor";
permission java.lang.RuntimePermission "setContextClassLoader";
permission java.lang.RuntimePermission "setFactory";
permission java.lang.RuntimePermission "setIO";
permission java.lang.RuntimePermission "setProtectionDomain";
permission java.lang.RuntimePermission "setSecurityManager";
permission java.lang.RuntimePermission "writeFileDescriptor";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission java.net.NetPermission "requestPasswordAuthentication";
permission java.net.NetPermission "setDefaultAuthenticator";
permission java.security.SecurityPermission "getPolicy";
permission java.security.SecurityPermission "setPolicy";
permission java.util.PropertyPermission "*", "read,write";
I dont know what is wrong here. In the weblogic.policy file,I tried
differrent combinations but it never worked.
I find weblogic documentation for troubleshooting to be pathetic.Notuseful
at all.Documentation looks
good to read ;not for practical purposes.I'm not sure whether others have
similar opinion.
I'm stuck at this thing for the past few days,I still have lot of work todo
to purusue our management team to buy weblogic
but I'm still stuck at this thing.
Thank you very much for your time.
Thanks,
Sravan
"Sravan Thella" <[email protected]> wrote in message
news:[email protected]...
Hi,
I'm new to weblogic server.I'm trying to setup weblogic 510.Everything
was
going fine until I got stuck to this small thing.I'm not able to load a
simple servlet!.
I would appreciate any pointers regarding this.Please Help me!!!
Here is what I tried:
I have installed weblogic510 plug-in for IIS.I could successfully runjsp
files.However I am not able to load simple servlets;It gave an exception
"java.lang.IllegalAccessError: try to access class
weblogic/utils/classloaders/FileSource from class
weblogic/servlet/internal/WarClassFinder"
Details of my configuration:
WebServer - IIS 4.0
IIS port=80
Weblogic port=7001
I had set it in such a way that all the requests first go to IIS andthen
IIS redirects them to Weblogic.I've followed the steps according to the
document "Installing the Weblogic ISAPI Plug-in".
I've registered the servlet in weblogic.properties as following:
weblogic.httpd.register.hello=examples.servlets.HelloWorld2
I tested the servlet by URL http://localhost:7001/hello
Following is the eact text for the exception I got in the WeblogicServer
window:
Mon Jul 24 12:13:13 PDT 2000:<E> <ServletContext-General> Error loading
servlet:
examples.servlets.HelloWorld2
java.lang.IllegalAccessError: try to access class
weblogic/utils/classloaders/Fi
leSource from class weblogic/servlet/internal/WarClassFinder
at
weblogic.servlet.internal.WarClassFinder.getSource(WarClassFinder.jav
a, Compiled Code)
at
weblogic.servlet.internal.WarClassFinder.getClassSource(WarClassFinde
r.java:110)
at
weblogic.utils.classloaders.GenericClassLoader.findLocalClass(Generic
ClassLoader.java:381)
at
weblogic.utils.classloaders.GenericClassLoader.reallyLoadClass(Generi
cClassLoader.java, Compiled Code)
at
weblogic.utils.classloaders.RecursiveReloadOnModifyClassLoader$Slave.
loadClass(RecursiveReloadOnModifyClassLoader.java:234)
at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClass
Loader.java:146)
at
weblogic.utils.classloaders.RecursiveReloadOnModifyClassLoader.findLo
calClass(RecursiveReloadOnModifyClassLoader.java:109)
at
weblogic.utils.classloaders.GenericClassLoader.reallyLoadClass(Generi
cClassLoader.java, Compiled Code)
at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClass
Loader.java:172)
at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClass
Loader.java:146)
at
weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubI
mpl.java:291)
at
weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.
java:164)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:99)
at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:742)
at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:686)
at
weblogic.servlet.internal.ServletContextManager.invokeServlet(Servlet
ContextManager.java:247)
at
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.jav
a:361)
at
weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java,Compiled
Code)
Mon Jul 24 12:13:13 PDT 2000:<E> <ServletContext-General> Servlet failed
with Ex
ception
I dont think there were any problems in the classpath or
servletpath;Basically WeblogicServer was able to locate the servlet butwhen
it tried to load the servlet it gave this exception.
I would appreciate any ideas/suggestions.
Thanks,
Sravan -
Run a simple servlet in WLS6.1
Hi,
I am new to WLS 6.1
I have a simple servlet that outputs a string on webpage.
I am trying to run this servlet using the WLS6.1
I have compiled the source code and copied the class file (MyFirstServlet.class)
into
D:\BEA\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\classes
I have the web.xml file in web-inf directory as below
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name> HelloWorld </servlet-name>
<servlet-class> HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> HelloWorld </servlet-name>
<url-pattern> HelloWorld </url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet> <servlet-name> MyFirstServlet </servlet-name> <servlet-class> MyFirstServlet
</servlet-class> </servlet>
<servlet-mapping> <servlet-name> MyFirstServlet </servlet-name> <url-pattern>
MyFirstServlet </url-pattern> </servlet-mapping>
</web-app>
HelloWorls is also another simple servlet.
then in the browser I give
http://localhost:7001/MyFirstServlet
this is the error I get
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given
of whether the condition is temporary or permanent.
If the server does not wish to make this information available to the client,
the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code
SHOULD be used if the server knows, through some internally configurable mechanism,
that an old resource is permanently unavailable and has no forwarding address.
what is the problem?
Please anyone help me in this matter!
Thanks in Advance
SP
Hi,
I am new to WLS 6.1
I have a simple servlet that outputs a string on webpage.
I am trying to run this servlet using the WLS6.1
I have compiled the source code and copied the class file (MyFirstServlet.class)
into
D:\BEA\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\classes
I have the web.xml file in web-inf directory as below
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name> HelloWorld </servlet-name>
<servlet-class> HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> HelloWorld </servlet-name>
<url-pattern> HelloWorld </url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet> <servlet-name> MyFirstServlet </servlet-name> <servlet-class> MyFirstServlet
</servlet-class> </servlet>
<servlet-mapping> <servlet-name> MyFirstServlet </servlet-name> <url-pattern>
MyFirstServlet </url-pattern> </servlet-mapping>
</web-app>
HelloWorls is also another simple servlet.
then in the browser I give
http://localhost:7001/MyFirstServlet
this is the error I get
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given
of whether the condition is temporary or permanent.
If the server does not wish to make this information available to the client,
the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code
SHOULD be used if the server knows, through some internally configurable mechanism,
that an old resource is permanently unavailable and has no forwarding address.
what is the problem?
Please anyone help me in this matter!
Thanks in Advance
SP
-
Unable to deploy a simple servlet using WAR file on Oracle9iAS v9.0.3
Hi All,
I am facing problem while deploying a simple servlet using WAR file on Oracle 9i App Server.
I have installed Oracle9iAS J2EE and Web Cache v9.0.3 on Windows 2000 server.
It includes:
- Oracle HTTP Server
- Oracle9iAS Containers for J2EE
- Oracle9iAS Web Cache
- Oracle Enterprise Manager
The release of installed Oracle9iAS is Release 2 (9.0.3)
I referred following link to Deploy Applications Using WAR file:
http://otn.oracle.com/products/ias/daily/sept12.html
As mentioned in this documentation I have followed following steps to deploy WAR file:
1] I have created a war file by name SimpleServlet.war. In SimpleServlet.war, there is a servlet by name Simple which prints time at which servlet was accessed.
2] I have modified <ora9ias_home>\j2ee\home\config\application.xml and added following web module entry:
<web-module id="SimpleServlet" path="../../home/applications/SimpleServlet.war" />
3] To make this module accessible from over the web, I have modified file
<ora9ias_home>\j2ee\home\config\default-web-site.xml and added following entry:
<web-app application="SimpleServlet" name="SimpleServlet" root="/SimpleServlet"/>
4] I saved both the files and started Oracle HTTP Server and accessed page as below:
http://<server>:7777/SimpleServlet/Simple
where Simple is servlet in SimpleServlet.war file.
In the browser, The page cannot be found is shown to user. I have verified that SimpleServlet.war is extracted to SimpleServlet folder under <ora9ias_home>\j2ee\home\applications folder. I found that Simple.class is stored under WEB-INF/classes folder and web.xml contains correct entry for url pattern for servlet Simple.
What else could be the problem? Am I placing the war file in wrong place or modifying application.xml or default-web-site.xml in a wrong directory?
This is very urgent. Please help me with your valuable comments on this.
Thanks in advance.
Regards,
SandeshHi All,
I am facing problem while deploying a simple servlet
using WAR file on Oracle 9i App Server.
I have installed Oracle9iAS J2EE and Web Cache v9.0.3
on Windows 2000 server.
It includes:
- Oracle HTTP Server
- Oracle9iAS Containers for J2EE
- Oracle9iAS Web Cache
- Oracle Enterprise Manager
The release of installed Oracle9iAS is Release 2
(9.0.3)
I referred following link to Deploy Applications
Using WAR file:
http://otn.oracle.com/products/ias/daily/sept12.html
As mentioned in this documentation I have followed
following steps to deploy WAR file:
1] I have created a war file by name
SimpleServlet.war. In SimpleServlet.war, there is a
servlet by name Simple which prints time at which
servlet was accessed.
2] I have modified
<ora9ias_home>\j2ee\home\config\application.xml and
added following web module entry:
<web-module id="SimpleServlet"
path="../../home/applications/SimpleServlet.war" />
3] To make this module accessible from over the web,
I have modified file
<ora9ias_home>\j2ee\home\config\default-web-site.xml
and added following entry:
<web-app application="SimpleServlet"
name="SimpleServlet" root="/SimpleServlet"/>
4] I saved both the files and started Oracle HTTP
Server and accessed page as below:
http://<server>:7777/SimpleServlet/Simple
where Simple is servlet in SimpleServlet.war file.
In the browser, The page cannot be found is shown to
user. I have verified that SimpleServlet.war is
extracted to SimpleServlet folder under
<ora9ias_home>\j2ee\home\applications folder. I found
that Simple.class is stored under WEB-INF/classes
folder and web.xml contains correct entry for url
pattern for servlet Simple.
What else could be the problem? Am I placing the war
file in wrong place or modifying application.xml or
default-web-site.xml in a wrong directory?
This is very urgent. Please help me with your
valuable comments on this.
Thanks in advance.
Regards,
SandeshHave you restarted you http server and then tried to load it again? Are you using the right port; maybe you have to use port 7778? Check you server settings in the http server instance. Also check your url binding of you application at Farm > Application Server: infrastructurehost > OC4J_instance > Application: appname > Web Module: modulename
Good luck!
rgds Thomas -
Unable to deploy a simple servlet using WAR file
Hi All,
I am facing problem while deploying a simple servlet using WAR file on Oracle 9i App Server.
I have installed Oracle 9i App Server. I referred following link to Deploy Applications Using WAR file:
http://otn.oracle.com/products/ias/daily/sept12.html
As mentioned in this documentation I have followed following steps to deploy WAR file:
1] I have created a war file by name SimpleServlet.war. In SimpleServlet.war, there is a servlet by name Simple which prints time at which servlet was accessed.
2] I have modified <ora9ias_home>\j2ee\home\config\application.xml and added following web module entry:
<web-module id="SimpleServlet" path="../../home/applications/SimpleServlet.war" />
3] To make this module accessible from over the web, I have modified file
<ora9ias_home>\j2ee\home\config\default-web-site.xml and added following entry:
<web-app application="SimpleServlet" name="SimpleServlet" root="/SimpleServlet"/>
4] I saved both the files and started Oracle HTTP Server and accessed page as below:
http://<server>:7777/SimpleServlet/Simple
where Simple is servlet in SimpleServlet.war file.
In the browser, The page cannot be found is shown to user. I have verified that SimpleServlet.war is extracted to SimpleServlet folder under <ora9ias_home>\j2ee\home\applications folder. I found that Simple.class is stored under WEB-INF/classes folder and web.xml contains correct entry for url pattern for servlet Simple.
What else could be the problem? Am I placing the war file in wrong place or modfiying application.xml or default-web-site.xml in a wrong directory?
This is very urgent. Please help me with your valuable comments on this.
Thanks in advance.
Regards,
SandeshHi Juliana,
Thanks a lot for your suggestion.
I am sorry if I have posted this message to a wrong forum. This is first time I am posting a message to OTN. I will resend message to J2EE forum as per you suggestion.
Meanwhile, please note information you asked for is as below:
I installed Oracle9iAS J2EE and Web Cache v9.0.3 on Windows 2000 server.
It includes:
- Oracle HTTP Server
- Oracle9iAS Containers for J2EE
- Oracle9iAS Web Cache
- Oracle Enterprise Manager
The release of installed Oracle9iAS is Release 2 (9.0.3)
Please do reply at the earliest.
Once again thanks and look forward to hear from you.
Regards,
Sandesh -
Calling simple Java Code from 11g BPM
Hi,
I know this has been round the houses but I cant find a satisfactory solution for my scenario. I would like to call some simple java code from BPM (11.1.1.6). I guess I need to expose it as a service but it seems overkill to be via soap so any advice you can give would be much appreciated. Creating a jar that I can call somehow would be perfect.
This is my scenario:
- I am creating a Security POC for BPM
- The BPM Process is exposed as a web service and authenticated using SAML
- I am testing by calling the WS from OSB
- I want to be able to get the WLS Principal and display the username and the roles for the launching user, from within the BPM process
- This is possible using some simple weblogic client api code shown below
- So all I want to do is call this code from BPM somehow
- Anyone point me in the right direction ?
cheers
Tony
subject = Security.getCurrentSubject();
for(Principal p: subject.getPrincipals()) {
if(p instanceof WLSGroupImpl) {
groupList.add(p.getName());
} else if (p instanceof WLSUser) {
principal = p.getName();
}The problem to communiate java classes and forms solved !
i have add my .jar file to $OA_JAVA/oracle/apps/fnd/jar and now i can communicate between forms and java.
I can create an object, i can get simple message from class, but when i try to create
ServiceFactory factory = ServiceFactory.newInstance();
ive got ORA-105100...
can anybody help ? -
Problem compiling simple servlet
I am trying to compile a very simple servlet.
When I do, I get the following error message:
Package javax.servlet does not exist
I am using the Java 2 SDK, Standard Edition Version 1.3.1.
I have downloaded the servlet api (zip file servletapi2_1_1win.zip)
from Sun's site. I unzipped these files in my lib directory; there are two folders,
one called api and the other called src. Api and Src directories have their own
sub-folders, javax/servlet/http etc.
I am using W2K ; I had to create a CLASSPATH system variable in the environment
variables section of control panel since there was none defined.
I added the following line:
C:\jdk1.3.1_01\lib\api\javax\servlet;C:\jdk1.3.1_01\lib\api\javax\servlet\http;
I also did this for the PATH statement..
My servlet looks like this:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class howdy extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello World </TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello World </BIG>");
out.println("</BODY></HTML>");Thanks. I was able to figure it out by specifying the
full classpath
at the command line, like this:
C:> javac -classpath
C:\jdk1.3.1_01\lib\servletapi2_1_1-win.zip\MyServlet.ja
a
Apparantly the system doesn't acknowledge the
environmental variable that
I created in the control panel; also I have no
autoexec.bat file...so it
looks like I have to write out the full path whenever
I need to compile
something. Kind of bothersome, but at least it
works.
You shouldn't have to do this. What operating system are you using?
If you are using win2000, winNT or winxp, you should set the classpath in your system environment varialbes. You can also make a config.bat file and put everything in there. Then just run this config.bat file to set up your environment once for every session.
Here's a file that I have set up on one of our NT machines. I just double click the icon for this file on my shortcut, and it gives me the window where I can compile my java programs.
Hope this helps.
Kamran
=========== File SetJava.bat ============
set PATH=%PATH%;m:\jdk1.3\bin
set CLASSPATH=m:\jdk1.3\jre\lib;m:\jdk1.3\jaxp-1.1\jaxp.jar;m:\jdk1.3\jaxp-1.1\crimson.jar;m:\jdk1.3\jaxp-1.1\xalan.jar;.
cd cis235
%SystemRoot%\system32\cmd.exe -
Flush parameter of jsp:include has no effect on servlet code
I am running 9.0.3 and my jsp code looks like:
<jsp:include page =".." flush="false"/>
but the resulting servlet code is:
pageContext.include( __url);
Which defaults to flushing the buffer!
Does anyone know a work around or if Oracle is going to fix this?
Thanks,
MikeTry:
public class ... extends ...
private static final boolean antialias = Boolean.getBoolean ("swing.aatext");
private static Map hintsMap = null;
@SuppressWarnings("unchecked")
static final Map getHints() {
if (hintsMap == null) {
hintsMap = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
if (hintsMap == null) {
hintsMap = new HashMap();
if (antialias) {
hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
return hintsMap;
... later in class ...
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.addRenderingHints(getHints());
super.paintComponent(g);
...needed this so custom paint would use AA. In my app I wrote text in my component and it was not AA, this turned it on.
I don't think I had the same problem you, as my jlabels were always aa.
Edited by: 805835 on Oct 27, 2010 5:06 PM
Edited by: 805835 on Oct 27, 2010 5:07 PM -
Please help with the simple servlet
hi all......
i am trying to write a servlet that accepts parameters from html and validates it against database and displays if the user is valid or not....
but my code always displays invalid user..........i don't know where i am going wrong.........kindly help
html code:
<html>
<body>
<form action=/LoginServlet>
<p><h1>
username:<input type=text name=nm>
<p>password:<input type=text name=pwd>
<p>
<input type=submit value=Login>
</form>
</body>
</html>
servlet code:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class name1 extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse
res) throws ServletException,IOException {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:nmpwd");
Statement stmt = con.createStatement();
res.setContentType("text/html");
PrintWriter out = res.getWriter();
ResultSet rs;
String r = req.getParameter("nm");
String r1 = req.getParameter("pwd");
String query="select * from namep";
rs = stmt.executeQuery(query);
String s="",s1="";
while(rs.next())
s = rs.getString(1);
s1 = rs.getString(2);
if(r.equals(s)&&r1.equals(s1))
out.println("VALID USER");
else
out.println("INVALID USER");
con.close();
}catch(Exception e) { }
}The JSP code is correct. Please change the servlet code. I have done the changes. It's Working correctly now.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class LoginServlet extends HttpServlet
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
System.out.println("Entered Servlet");
try
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@bslblrora9i:1521:blrora1","javauser","javauser");
res.setContentType("text/html");
PrintWriter out = res.getWriter();
ResultSet rs=null;
String r = req.getParameter("nm");
String r1 = req.getParameter("pwd");
PreparedStatement stmt=con.prepareStatement("SELECT * FROM NAMEP");
rs=stmt.executeQuery();
int flag=0;
String s="";
String s1="";
while (rs.next())
s=rs.getString(1);
s1=rs.getString(2);
if (r.equals(s))
if (r1.equals(s1))
flag=1;
if (flag==1)
out.println("valid User");
else
out.println("Invalid User");
con.commit();
con.close();
catch(Exception e)
System.out.println("Error "+e);
} -
How to retrieve "env-entry" in servlet code
i have a pretty straight-forward web app, which contains a servlet, among other things. the web app is packaged in .war, and it in turn is part of a .ear file. i am using WAS 640 sneak preview on windows xp.
in the web.xml file, i added the following lines:
<env-entry>
<description>some texts</description>
<env-entry-name>myapp.home</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>c:/myapp</env-entry-value>
</env-entry>
in my servlet code, i try to retrieve the value for "myapp.home" like this:
try
Context ctx = new InitialContext();
home = (String) ctx.lookup("java:comp/env/myapp.home");
} catch (Exception ex) {
ex.printStackTrace();
after .ear is deployed, i can see in the JDNI Registry (using Visual Admin Tool), myapp.home is added to the tree:
webContainer
-applications
--myCompany.com
---myEarFileName
myWebAppRoot
java:comp
env
myapp.home
the entry has the correct class name and object value.
when the servlet code that performs the jndi lookup is called, i get an exception:
com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at : java:comp
??? QUESTIONS:
#1 what am i doing wrong?
#2 if the lookup name must contain the entire jndi tree as listed above, then how can this code be portable to other app servers?
thoughts are greatly appreciated.thanks for the hints, but unfortunately they didn't work.
1. after switching the order of value and type in env-entry, rebuild/redeplpoy, same exception. the ordering probably didn't matter since even with the reversed order, the name and value showed up correctly under the jndi tree.
2. well, i tried giving it the full path, starting with 'webContainer', then 'applications' etc, separated by forward slash. now the exception says path to webContainer is not found.
so what gives? are there no standards? -
How to translate this statement to java servlet code
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)You wouldn't translate that statement to servlet code. The idea doesn't make any sense. However you might include it in a servlet; read the tutorial that zadok linked to.
Maybe you are looking for
-
Automaticly print to pdf without file name prompt
Hi, I am building an aplication that uses "Report Generation Toolkit". I am creating a "word" report with a template. After I am done with word creation I want to convert this "word" report to "PDF" format. I need that this process will be an automat
-
Check out the new pic of this board on Newegg.com - what is going on? It says PLATINUM but gone are the solid caps, SPDIF, Ex.SATA, Copper heatsinks/tubing!!!!!!!!!!!!! Is this a joke?!? It looks just like the normal P6N.... there must be a mistake!!
-
Questions on dual booting with win8 and efi
Hello folks, I have windows 8.1 set up on /dev/sdb in efi mode and would like to install arch linux on /dev/sda Fast startup on win8 is disabled aswell as secure boot. Now, my questions: 1) Do I create an efi system partition on /dev/sda or do I use
-
I entered the correct password in the password dialogue in Mail, but continue to be asked for the password
-
Fonts and indent first line in adobe forms
Hi, I have a smartstyle with paragraph format DF for which <b>left margin</b> is <b>1.00cm</b> and <b>indent first line</b> is <b>-1.00cm</b>. I am using this style in textmodule where i can see the text correctly as desired. but when i am using this