subi phoenix

Greenhorn
+ Follow
since Jul 13, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by subi phoenix

Hi,
I am trying to read from a property file using the following code. I dont get the value for "name" key. So I tried to read the number of keys in the file, that too return 0. Could you please help me.

Code:
----------


static String rateFinder()
{
int elen=0;
Properties props=new Properties();

try
{
props.load( new FileInputStream(new File("test.properties")));
}
catch(IOException ie)
{
System.out.println("Error reading file");
}
// String key = "name";
// String val = props.getProperty(key,"notfound");

Enumeration enum = props.keys();
while(enum.hasMoreElements())
{
elen+=1;
}
return Integer.toString(elen);
}


test.properties
----------------------
name=subi
roll=101
mark1=100

*****
Both the files are in same location, indeed i do not get IOException. It seems the method reads the file but not the contents.

I have to use static method as i read the returned value in a method which should take only static values.

Pls help.

Thanks,
subi.
18 years ago
Before executing this i have set my path & classpath;


C:\bea\user_projects\domains\mydomain>set path=%path%;c:\j2sdk1.4\bin;.;

C:\bea\user_projects\domains\mydomain>set classpath=%classpath%;.;C:\bea\weblogic81\server\bin\weblogic.jar

Pls help
Thank you Valentin,

I tried but i got this different exception:

C:\bea\user_projects\domains\mydomain\myEJB>java Client
Before lookup
Got Initial Context
Called From Client Catch
javax.naming.NameNotFoundException: Unable to resolve 'StatelessSessionHome' Resolved ; remaining name 'State
lessSessionHome'
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244)
at weblogic.jndi.internal.ServerNamingNode_811_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:338)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:333)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at Client.main(Client.java:18)
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'StatelessSessionHome' Resolved
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:869)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:230)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:166)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:188)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:466)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:409)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:353)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:144)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:404)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)


But all my classes are in the same directory.

Pls help me out.
Hi,

I deployed a stateless session bean in weblogic 8.1
successfully. But when I run client program from command prompt i got the following exception.

C:\bea\user_projects\domains\mydomain\myEJB>java Client
Before lookup
Called From Client Catch
javax.naming.NoInitialContextException: Cannot
instantiate class: weblogic.jndi.WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: web
logic.jndi.WLInitialContextFactory]

at javax.naming.spi.NamingManager.getInitialContext(Unknown
Source)
at Javax.naming.InitialContext.getDefaultInitCtx(UnknownSource)
at javax.naming.InitialContext.init(UnknownSource)
at javax.naming.InitialContext.<init>(Unknown Source)
at Client.main(Client.java:16)

Caused by: java.lang.ClassNotFoundException:
weblogic.jndi.WLInitialContextFactory
at java.net.URLClassLoader$1.run(UnknownSource)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown
Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown
Source)
... 5 more



Source Code:


Home Interface:

import javax.ejb.*;
import java.rmi.*;

public interface StatelessSessionHome extends EJBHome
{
public StatelessSession create() throws RemoteException,CreateException;
}






Remote Interface:

import javax.ejb.*;
import java.rmi.*;

public interface StatelessSession extends EJBObject
{
public String getName() throws RemoteException;
public void setName(String stName) throws RemoteException;
}



EJB Class:
import javax.ejb.*;
import javax.naming.*;

public class StatelessSessionEJB implements SessionBean
{
private SessionContext ctx;
private String strName;
public void ejbActivate(){
System.out.println("ejbActivate ("+strName+")called.");
}

public void ejbRemove()
{
System.out.println("ejbRemove("+strName+")Called.");
}

public void ejbPassivate()
{
System.out.println("ejbPassivate("+strName+")called.");
}

public void setSessionContext(SessionContext ctx)
{
System.out.println("setSessionContext()called.");
this.ctx = ctx;
}

public void ejbCreate() throws CreateException
{
System.out.println("ejbCreate() called");
}
public void setName(String value)
{
strName = value;
System.out.println("setName("+strName+")called.");
}
public String getName()
{
System.out.println("getName("+strName+")called.");
return strName;
}
}


Client.java

import javax.naming.*;
import javax.rmi.*;
import java.rmi.*;
import java.util.*;

public class Client
{
public static void main(String args[])
{
try
{
System.out.println("Before lookup");
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL,"t3://localhost:7001" );
InitialContext ctx = new InitialContext(prop);
System.out.println("Got Initial Context");
StatelessSessionHome home = (StatelessSessionHome)ctx.lookup("StatelessSessionHome");
StatelessSession rem = home.create();
System.out.println("create called");
System.out.println("Getting name from Bean");
String name = rem.getName();
System.out.println("Name : "+name);
System.out.println("Setting name to Bean");
rem.setName(args[0]);
Thread.sleep(1000);
name = rem.getName();
System.out.println("Name : "+name);
}

catch(Exception er)
{
System.out.println("Called From Client Catch");
er.printStackTrace();
}
}
}


On the command prompt (server) prompt I got these:
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called

seems somewhere problem in creating the initial context.

Could you enlighten me where is wrong?Please..

Hi,

I deployed a stateless session bean in weblogic 8.1
successfully. But when I run client program from command prompt i got the following exception.

C:\bea\user_projects\domains\mydomain\myEJB>java Client
Before lookup
Called From Client Catch
javax.naming.NoInitialContextException: Cannot
instantiate class: weblogic.jndi.WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: web
logic.jndi.WLInitialContextFactory]

at javax.naming.spi.NamingManager.getInitialContext(Unknown
Source)
at Javax.naming.InitialContext.getDefaultInitCtx(UnknownSource)
at javax.naming.InitialContext.init(UnknownSource)
at javax.naming.InitialContext.<init>(Unknown Source)
at Client.main(Client.java:16)

Caused by: java.lang.ClassNotFoundException:
weblogic.jndi.WLInitialContextFactory
at java.net.URLClassLoader$1.run(UnknownSource)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown
Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown
Source)
... 5 more



Source Code:


Home Interface:

import javax.ejb.*;
import java.rmi.*;

public interface StatelessSessionHome extends EJBHome
{
public StatelessSession create() throws RemoteException,CreateException;
}






Remote Interface:

import javax.ejb.*;
import java.rmi.*;

public interface StatelessSession extends EJBObject
{
public String getName() throws RemoteException;
public void setName(String stName) throws RemoteException;
}



EJB Class:
import javax.ejb.*;
import javax.naming.*;

public class StatelessSessionEJB implements SessionBean
{
private SessionContext ctx;
private String strName;
public void ejbActivate(){
System.out.println("ejbActivate ("+strName+")called.");
}

public void ejbRemove()
{
System.out.println("ejbRemove("+strName+")Called.");
}

public void ejbPassivate()
{
System.out.println("ejbPassivate("+strName+")called.");
}

public void setSessionContext(SessionContext ctx)
{
System.out.println("setSessionContext()called.");
this.ctx = ctx;
}

public void ejbCreate() throws CreateException
{
System.out.println("ejbCreate() called");
}
public void setName(String value)
{
strName = value;
System.out.println("setName("+strName+")called.");
}
public String getName()
{
System.out.println("getName("+strName+")called.");
return strName;
}
}


Client.java

import javax.naming.*;
import javax.rmi.*;
import java.rmi.*;
import java.util.*;

public class Client
{
public static void main(String args[])
{
try
{
System.out.println("Before lookup");
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL,"t3://localhost:7001" );
InitialContext ctx = new InitialContext(prop);
System.out.println("Got Initial Context");
StatelessSessionHome home = (StatelessSessionHome)ctx.lookup("StatelessSessionHome");
StatelessSession rem = home.create();
System.out.println("create called");
System.out.println("Getting name from Bean");
String name = rem.getName();
System.out.println("Name : "+name);
System.out.println("Setting name to Bean");
rem.setName(args[0]);
Thread.sleep(1000);
name = rem.getName();
System.out.println("Name : "+name);
}

catch(Exception er)
{
System.out.println("Called From Client Catch");
er.printStackTrace();
}
}
}


On the command prompt (server) prompt I got these:
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called
setSessionContext()called.
ejbCreate() called

seems somewhere problem in creating the initial context.

Could you enlighten me where is wrong?Please..
I also came to know that there are other patterns like below could be used in Struts. But the confusion is which to use when?

Session Facade (for entity Beans)
DAO
DVO
Service Locator
Business Delegates
In an interview they asked.
Hi,

What are design patterns used in struts(except MVC)?
Hello,

Can any one pls tell, what is the difference between the struts framework and the spring framework and which is preferred in what context?
Hello all,

I here posts the steps i carried out to execute the
servlet. If anyone have different idea pls post.

Steps to create your directory and work in Tomcat 4.1

1.Create your directory in Tomcat�s webapps
Directory.
�If your tomcat is in d:\ the your directory may look
�D:\tomcat\webapps\<your directory>
�E.g. �d:\tomcat\webapps\test�
2.In the test directory you can your html files
directly or you can create a directory to hold html
files.
�E.g. �d:\tomcat\webapps\test\first.html (OR)
�E.g. �d:\tomcat\webapps\test\html-files\first.html�
3.Create a folder called WEB-INF inside test
�E.g. �d:\tomcat\webapps\test\WEB-INF
�Under the WEB-INF folder put your web.xml file
4.Create another folder named classes under the same
test
�E.g. �d:\tomcat\webapps\test\classes
�Here you need to place your servlet classes
�E.g.
�d:\tomcat\webapps\test\classes\testServlet.class
5.Start any browser that are java enabled
6.Type �http://<machine name (or) IP add.
>:8080/<your folder name>/<html file>�
�E.g. http://localhost:8080/test/ html-files
/first.html
�E.g.
http://127.0.0.1:8080/test/html-files/first.html
7.Click the component (button, label�) to enable
servlet
8.That�s all! Now you should get your servlet
executed.

Files:

1.web.xml

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>
<servlet-name>testServlet</servlet-name>
<servlet-class>testServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/testServlet/*</url-pattern>
</servlet-mapping>

</web-app>


2. first.html
<html>
<body>
<form method="POST"
action="http://localhost:8080/test/testServlet">
<input type=submit value=click></input>
</form>
</body>
</html>

3. testServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class testServlet extends HttpServlet
{
public void doPost(HttpServletRequest req,
HttpServletResponse res)throws ServletException,
IOException
{
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<h1>Hello! </h1>");
out.println("</body>"+"</html>");
}
}

I have put my first.html inside the folder
�d:\tomcat\webapps\test\html-files\� and testServlet
is under �d:\tomcat\webapps\test\WEB-INF\classes\� folder.
18 years ago
Thnank you all.

Now it works after i have moved my classes directory into WEB-INF folder.
18 years ago
Hello,

I have only one class in my classes directory:TestServlet.class. And it is a statndalone class no package defiend.

please tell now what should i do?

Thank you,
Subi
18 years ago
Hello,

I am using Tomcat 4.1. I just started working in it,
so this asking may be childish, if so, pls don�t
mistake me.

Here is my webapp structure:

1. C:\Program Files\Apache Group\Tomcat 4.1\webapps\testapp\classes
-----here i have my servlet classes
2. C:\Program Files\Apache Group\Tomcat 4.1\webapps\testapp\jsp
-----here i have a sample.htm file
3. C:\Program Files\Apache Group\Tomcat 4.1\webapps\testapp\WEB-INF
-----here is the web.xml resides

my web.xml entry is like this:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
</web-app>

------------------
the sample.htm has the following entries:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body>
<p><font color="#000099">Hello, Welcome!</font> </p>
<form action="http:\\localhost:8080\testapp\TestServlet"
method="post" name="form1" target="_self">

<input type="submit" name="Submit" value="Click Me">
</form>

</body>
</html>

---------------

Here is what I done:
1. I started the Tomcat server
2. opened "http://localhost:8080/testapp/jsp/sample.htm"
3. clicked the button which gives the error "http 500 the TestServlet was not found"



Also please let me know in which folder should I put servlet,jsp and other files. Do I have to follow any structure/format?

Please tell me what is the problem?

Thank you!
18 years ago
Hello Macky,

Thanks for the help. I dont have DB2 installed in my machine. I will try again after installing DB2.

Thank you.
18 years ago
I am using windows 2000 server. While installing the websphere application server 3.5, I face a strange problem. It goes well till the 99%, but here it asks for a file "Db2udbee.rsp" (DB2 Install image). I searched entire CD but there is no such file.

The installation process does not move further. Please help me out.
18 years ago