Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

jari bharat

Greenhorn
+ Follow
since Jan 14, 2002
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 jari bharat

I have problem when i accessing my JNDI tree in browser.i get following error when i click on java:comp node.
javax.naming.NameNotFoundException: Unable to resolve comp. Resolved: '' Unresolved:'comp' ; remaining name ''
<>
19 years ago
guys ,,
mock exam available for free download at :
http://www.whizlabs.com/weblogic/try.html
19 years ago
Hi ,
please help me.when i open JNDI tree i can view it in left pane indicating javax ,weblogic and java:comp node.but when i click on java:comp node i get following error.
javax.naming.NameNotFoundException: Unable to resolve comp. Resolved: '' Unresolved:'comp' ; remaining name ''

is there any solution.
19 years ago
thanks ,
now i get solution.first i set classpath to weblogic.jar and execute command.it work now.
19 years ago
thanks ,
i have put weblogic.jar in classpath. but still same problem.
19 years ago
Im using weblogic6.1 and i want to know how to deploy an application in the server.
im using this command
java weblogic.deploy -host hostName -port 7001 deploy weblogicPassword applicationNae app.ear
this gives
JNDI naming exception: Naming exception trying to connect to t3://hostName:7001 as: system:weblogicPassword

It works when im running from the same machine as my server.
Please help me
Regards
Cherry
19 years ago
Hello all,
here is step-by-step for creating JMS(Topic) messaging example.i have used code/explanation from BEA code examples so that u can better understand JMS API.

---------------------------------------------------------------------------------
1.Managing JMS :
To configure WebLogic JMS attributes, perform the following steps:

1.Start the Administration Console.
2.Select the JMS button under Services in the left pane to expand the list.
3.Follow the procedures described in the following sections
i) Configuring Connection Factories
Name : MyJMS Connection Factory
JNDIName : example.jms.TopicConnectionFactory
all others are default.
Target : your hostname.
ii) Configuring Stores
The backing store consists of a file or database that is used for persistent messaging.
in our case user "Configure a new JMSFile Store..."
ii) Configuring Servers
Name : MyJMSServer
Store : default
ii) Configuring Destination
Name : MyJMSTopic
JNDIName : example.jms.exampleTopic

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

1. Application Development Flow
When developing a WebLogic JMS application, you must perform the steps identified in the following figure

i) Include the following package import statements at the beginning of your program:

import javax.jms.*;import java.util.*;import java.io.*;import javax.naming.*;import javax.transaction.*;
ii) Setting Up a JMS Application
Figure 2 Setting Up a JMS Application

--------------------------------------------------------------------
Classes Code
code for Topic Receiver.java
package example.jms;
import java.io.*;
import java.util.*;
import javax.transaction.*;
import javax.naming.*;
import javax.jms.*;
/**
*
* This example shows how to establish a connection to and receive
* messages from a JMS topic. The classes in this package operate
* on the same JMS topic. Run the classes together to observe messages
* being sent and received. This class is used to receive messages from
* the topic.
* @author Copyright (c) 1999-2001 by BEA Systems, Inc. All Rights Reserved.
*/
public class TopicReceive
implements MessageListener
{
/**
* Defines the JNDI context factory.
*/
public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
/**
* Defines the JMS connection factory for the topic.
*/
public final static String JMS_FACTORY="example.jms.TopicConnectionFactory";
/**
* Defines the topic.
*/
public final static String TOPIC="example.jms.exampleTopic";
private TopicConnectionFactory tconFactory;
private TopicConnection tcon;
private TopicSession tsession;
private TopicSubscriber tsubscriber;
private Topic topic;
private boolean quit = false;
/**
* Message listener interface.
* @param msg message
*
*/
// MessageListener interface
public void onMessage(Message msg)
{
try {
String msgText;
if (msg instanceof TextMessage) {
msgText = ((TextMessage)msg).getText();
} else {
msgText = msg.toString();
}
System.out.println("JMS Message Received: "+ msgText );
if (msgText.equalsIgnoreCase("quit")) {
synchronized(this) {
quit = true;
this.notifyAll(); // Notify main thread to quit
}
}
} catch (JMSException jmse) {
jmse.printStackTrace();
}
}
/**
* Creates all the necessary objects for sending
* messages to a JMS topic.
*
* @param ctx JNDI initial context
* @param topicNamename of topic
* @exception NamingExceptionif problem occurred with JNDI context interface
* @exception JMSException if JMS fails to initialize due to internal error
*/
public void init(Context ctx, String topicName)
throws NamingException, JMSException
{
tconFactory = (TopicConnectionFactory) ctx.lookup(JMS_FACTORY);
tcon = tconFactory.createTopicConnection();
tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = (Topic) ctx.lookup(topicName);
tsubscriber = tsession.createSubscriber(topic);
tsubscriber.setMessageListener(this);
tcon.start();
}
/**
* Closes JMS objects.
*
* @exception JMSException if JMS fails to close objects due to internal error
*/
public void close()
throws JMSException
{
tsubscriber.close();
tsession.close();
tcon.close();
}
/**
* main() method.
*
* @params args WebLogic Server URL
* @exception Exception if execution fails
*/
public static void main(String[] args)
throws Exception
{
if (args.length != 1) {
System.out.println("Usage: java examples.jms.topic.TopicReceive WebLogicURL");
return;
}
InitialContext ic = getInitialContext(args[0]);
TopicReceive tr = new TopicReceive();
tr.init(ic, TOPIC);
System.out.println("JMS Ready To Receive Messages (To quit, send a \"quit\" message).");
// Wait until a "quit" message has been received.
synchronized(tr) {
while (! tr.quit) {
try {
tr.wait();
} catch (InterruptedException ie) {}
}
}
tr.close();
}
private static InitialContext getInitialContext(String url)
throws NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
env.put("weblogic.jndi.createIntermediateContexts", "true");
return new InitialContext(env);
}
}
code for TopicSend.java
package example.jms;
import java.io.*;
import java.util.*;
import javax.transaction.*;
import javax.naming.*;
import javax.jms.*;
/**
* This examples shows how to establish a connection and send messages to the
* JMS topic. The classes in this package operate on the same topic. Run
* the classes together to observe message being sent and received. This
* class is used to send messages to
* the topic.
*
* @author Copyright (c) 1999-2001 by BEA Systems, Inc. All Rights Reserved.
*/
public class TopicSend
{
/**
* Defines the JNDI context factory.
*/
public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
/**
* Defines the JMS connection factory.
*/
public final static String JMS_FACTORY="example.jms.TopicConnectionFactory";
/**
* Defines the topic.
*/
public final static String TOPIC="example.jms.exampleTopic";
protected TopicConnectionFactory tconFactory;
protected TopicConnection tcon;
protected TopicSession tsession;
protected TopicPublisher tpublisher;
protected Topic topic;
protected TextMessage msg;
/**
* Creates all the necessary objects for sending
* messages to a JMS Topic.
*
* @param ctx JNDI initial context
* @param topicName name of topic
* @exception NamingExcpetion if problem occurred with the JNDI context interface
* @exception JMSException if JMS fails to initialize due to internal error
*
*/
public void init(Context ctx, String topicName)
throws NamingException, JMSException
{
tconFactory = (TopicConnectionFactory) ctx.lookup(JMS_FACTORY);
tcon = tconFactory.createTopicConnection();
tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = (Topic) ctx.lookup(topicName);
tpublisher = tsession.createPublisher(topic);
msg = tsession.createTextMessage();
tcon.start();
}
/**
* Sends a message to a JMS topic.
*
* @params message message to be sent
* @exception JMSException if JMS fails to send message due to internal error
*
*/
public void send(String message)
throws JMSException
{
msg.setText(message);
tpublisher.publish(msg);
}
/**
* Closes JMS objects.
*
* @exception JMSException if JMS fails to close objects due to internal error
*/
public void close()
throws JMSException
{
tpublisher.close();
tsession.close();
tcon.close();
}
/**
* main() method.
*
* @param args WebLogic Server URL
* @exception Exception if operation fails
*/
public static void main(String[] args)
throws Exception
{
if (args.length != 1) {
System.out.println("Usage: java examples.jms.topic.TopicSend WebLogicURL");
return;
}
InitialContext ic = getInitialContext(args[0]);
TopicSend ts = new TopicSend();
ts.init(ic, TOPIC);
readAndSend(ts);
ts.close();
}
/**
* Prompts, reads, and sends a message.
*
* @param ts TopicSend
* @exception IOException if problem occurs during read/write operation
* @exception JMSException if JMS fails due to internal error
*/
protected static void readAndSend(TopicSend ts)
throws IOException, JMSException
{
BufferedReader msgStream = new BufferedReader (new InputStreamReader(System.in));
String line=null;
do {
System.out.print("Enter message (\"quit\" to quit): ");
line = msgStream.readLine();
if (line != null && line.trim().length() != 0) {
ts.send(line);
System.out.println("JMS Message Sent: "+line+"\n");
}
} while (line != null && ! line.equalsIgnoreCase("quit"));
}
/**
* Get initial JNDI context.
*
* @params url Weblogic URL.
* @exception NamingException if problem occurs with JNDI context interface
*/
protected static InitialContext getInitialContext(String url)
throws NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
env.put("weblogic.jndi.createIntermediateContexts", "true");
return new InitialContext(env);
}
}
----------------------------------------------------------------------------------------------
Application Deployment
1. create example/jms directory under WEB-INF/classes directory in your web application root:
complete dir structure :
app. root/WEB-INF/classes/example/jms
2.put both java class under this dir.
3. compile the code(TopicReceiver.java and TopicSend.java)
----------------------------------------------------------------------------
Run Application.
a. from command window type following command:
(for Receiver)classes>java example.jms.TopicReceive t3://hostname:7001
(for Sender)classes>java example.jms.TopicSend t3://hostname:7001

---------------------------------------------------------
that's all for JMS Topic Messaging.
20 years ago
Hello all ,
this is my work, step-by-step creating custom tag library for jsp page running under weblogic server.

-----------------------------------------------------------------------------------
1. Tag class (Hello.java)
package example;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
* This is a simple tag example to show how content is added to the
* output stream when a tag is encountered in a JSP page.
*/
public class Hello extends TagSupport {
private String name=null;
/**
* Getter/Setter for the attribute name as defined in the tld file
* for this tag
*/
public void setName(String value){
name = value;
}
public String getName(){
return(name);
}
/**
* doStartTag is called by the JSP container when the tag is encountered
*/
public int doStartTag() {
try {
JspWriter out = pageContext.getOut();
out.println("<table border='\1\'>");
if (name != null)
out.println("<tr><td> Hello " + name + " </td></tr>");
else
out.println("<tr><td> Hello World </td></tr>");
} catch (Exception ex) {
throw new Error("All is not well in the world.");
}
// Must return SKIP_BODY because we are not supporting a body for this
// tag.
return SKIP_BODY;
}
/**
* doEndTag is called by the JSP container when the tag is closed
*/
}

-----------------------------------------------------------------------------
2 . Tag Library Descriptor
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tag>
<name>hello</name>
<tagclass>example.Hello </tagclass>
<attribute>
<name>name</name>
<required>false</required>
<rtexpvalue>false</rtexpvalue>
</attribute>
</tag>
</taglib>

-----------------------------------------------------------------------------
3. web.xml File
<?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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>tagTLD</taglib-uri>
<taglib-location>WEB-INF/library.tld</taglib-location>
</taglib>
</web-app>
-------------------------------------------------------------------------------
4. jsp file calling tag (Tag.jsp)
<%@ taglib uri="tagTLD" prefix="samples" %>
<html>
<head>
<title>Your Standard Hello World Demo</title>
</head>
<body bgcolor="#ffffff">
<hr />
<samples:hello name="jari" />
<hr />
</body>
</html>

----------------------------------------------------------------------
5.Deployment
1.copy/put compile class(Tag.class) to the following directory.
App root/WEB-INF/classes/example/Tag.class
2.copy/put web.xml in WEB-INF directory.
3.copy/put library.tld in WEB-INF directory.
4.Copy.put Tag.jsp in root directory.

-----------------------------------------------------
that's all your tag is ready you can view jsp file :
http://hostname:7001/Tag.jsp
hope this series of threads will usefull for all Weblogic developer.i will be continue with other weblogic features.
bye then
bharat
20 years ago
dear all,
so far i have covered Database , EJB access in servelet.in this thread i am going to give you example for JavaBean used in jsp page running under weblogic server.


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

JavaBean Class code(jspBeanTest.java)
package example;
import java.io.Serializable;
public class jspBeanTest
implements Serializable{
private String size = "Medium";
public void setSize(String size){
this.size = size;
}//end setSize()
public String getSize(){
return size;
}//end getSize()
public String exposedMethod(){
return "The size is " + size;
}//end exposedMethod()
}//end class jspBeanTest

-----------------------------------------------------------------------------------------------------
JSP page code(size.jsp)
<html>
<body>
<P>Examplep<BR><BR>
<P> Create or locate an instance of the<BR>
bean named:<BR><BR>
example.jspBeanTest.
<jsp:useBean
id="theBean"
scope="page"
class="example.jspBeanTest" />
<P>Display default size property of the <BR>
bean using the getter mehod.<BR><BR>
<%= theBean.getSize() %>
<P>Set the size property of the bean to<BR>
Large using the setter method.<BR><BR>
<% theBean.setSize("Large"); %>
<P>Get and display the size property<BR>
again using the getter method.<BR><BR>
<%= theBean.getSize() %>
<P>Invoke an exposed method on the bean.
<BR><BR>
<%= theBean.exposedMethod() %>
<P>Have a good day.
</body>
</html>

----------------------------------------------------------------------------------
deployment
1. create Directory structure like this :
App root -
-\WEB-INF
-\classes
-\example
2.put your compile class file of JavaBean in example directory.
3.put your jsp file in root directory.as jsp does not required entry in deployment desc. your work is over.

---------------------------------------------------------------------------------
run the server and type in address bar :
http://hostname:7001/size.jsp
bye
bharat
SCJP2
20 years ago
dear all,
i am new to J2ee technology.in last thread i have post complete step-by-step for accessing access database from servlet running in weblogic.in this this thread i am providing step-by-step for creating Session bean and calling it from Servlet.

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

Creating Session Bean
1. Creating Home Interface :
import javax.ejb.*;
import java.rmi.*;
public interface SimpleHome extends EJBHome{
public Simple create() throws remoteException, CreateException;
}

2.create Remote Interface :
import javax.ejb.*;
import java.rmi.*;
public interface Simple extends EJBObject
{
public String sayHello() throws RemoteException;
}

Creating Bean
import javax.ejb.*;
public class SimpleBean implements SessionBean
{

private SessionContext _sessionContext;

// -----------------------------------------------------
// --- Implementation of the Simple interface ----------
// -----------------------------------------------------
public String sayHello()
{
return "Hello, Enterprise!";
}
// -----------------------------------------------------
// --- EJB methods -------------------------------------
// -----------------------------------------------------
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
public void ejbRemove()
{
}
public void ejbCreate()
{
}
public void setSessionContext(SessionContext sessionContext)
{
_sessionContext = sessionContext;
}
}
-----------------------------------------------------------------------------------------------------------------------
Creating Servlet that call Bean
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
public class Test extends HttpServlet {
SimpleHome home;
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try{
Hashtable ht = new Hashtable();
PrintWriter out = response.getWriter();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://hostname:7001");

InitialContext ctx = new InitialContext(ht);
Object objref = ctx.lookup("Simple");
home =(SimpleHome)PortableRemoteObject.narrow(
objref,
SimpleHome.class);
out.println(home.create().sayHello());
}
catch (Exception NamingException) {
NamingException.printStackTrace();
}

}
public void destroy() {
System.out.println("Destroy");
}
}

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

Creating web.xml file
<?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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>Test</url-pattern>
</servlet-mapping>
</web-app>

---------------------------------------------------------------------------------------------------------
creating ejb-jar.xml file
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Simple</ejb-name>
<home>SimpleHome</home>
<remote>Simple</remote>
<ejb-class>SimpleBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor></assembly-descriptor>
</ejb-jar>
----------------------------------------------------------------------------------------------
creating weblogic-ejb-jar.xml file
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC
"-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN"
"http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd" >
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Simple</ejb-name>
<jndi-name>Simple</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

-------------------------------------------------------------------------------------------------------
Deploying Application
Deploying EJB
1.creat temp staging directory.
2.add all ejb class file in root.
3.create META-INF directory as sub-directort of temp.
4. add ejb-jar.xml and weblogic-ejb-jar.xml in it.
5. create jar file by following command.
temp> jar cvf Simple.jar *.*
Deploying Servlet
1.if your are using default web application then add all class file (including ejb classes) in WEB-INF/classes subdirectory located inside default Application folder.
2.add web.xml file in WEB-INF folder.

--------------------------------------------------------------------------------------------
that's all now u are ready to run your servlet from browser by :
http://hostname ort/Test
20 years ago
Hello all,
yesterday i have posted Question Regarding how to Connect Access with Servlet running in Weblogic Server?.i have got solution now.so here is what i have made step-by-step:

1. create DSN through Control Panel.
2. In weblogic Console i have Set various Properties for DataBase Service Node Like :
  • ConnectionPool

  • 1.Name - JDBCAccessPool
    2.URL - jdbc:odbc:Db
    3.Driver Classname - sun.jdbc.odbc.JdbcOdbcDriver
    4.Poperties : -user=node
    password=none
    server=none
  • Data Sources

  • 1.Name - MyJDBC Data Source[/list]
    2.JNDI Name - MyDataBase
    3.Pool Name - JDBCAccessPool
    -------------------------------------------------
    Servlet code is as follow :
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import javax.naming.*;
    public class HelloWordServlet extends HttpServlet {
    public void doGet(HttpServletRequest req,
    HttpServletResponse res) throws IOException{
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    String name=req.getParameter("name");
    out.println("<html><head><title>Hello World!");
    out.println("</title></head>");
    out.println(name);
    Context ctx = null;
    Hashtable ht = new Hashtable();
    ht.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    ht.put(Context.PROVIDER_URL,
    "t3://jariwalabd:7001");
    try {
    ctx = new InitialContext(ht);
    javax.sql.DataSource ds
    = (javax.sql.DataSource) ctx.lookup ("MyDataBase");
    java.sql.Connection conn = ds.getConnection();
    // You can now use the conn object to create
    // Statements and retrieve result sets:
    Statement stmt = conn.createStatement();
    stmt.execute("select * from Directory");
    ResultSet rs = stmt.getResultSet();
    while (rs.next()) {
    String s = rs.getString("NAME");
    out.println(s);
    }
    // Close the statement and connection objects when you are finished:
    stmt.close();
    conn.close();
    }
    catch (NamingException e) {
    // a failure occurred
    }
    catch (Exception e) {
    out.println(e);
    }
    finally {
    try {ctx.close();}
    catch (Exception e) {
    // a failure occurred
    }
    }
    out.println("<body><h1>Hello !</h1></body></html>");
    }
    }

    -----------------------------------------------
    [ July 30, 2002: Message edited by: Marilyn de Queiroz ]
    20 years ago
    i am new to Weblogic Server. i am trying to connect access database in servlet the code for servlet is here.
    Driver myDriver = (Driver)Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    Properties props = new Properties();
    props.put("connectionPoolID", "JDBCAccessPool");
    Connection conn =myDriver.connect("jdbc:weblogic ool:JDBCAccessPool",null);
    Statement st=conn.createStatement();
    String query = "SELECT * from directory";
    ResultSet rs = st.executeQuery(query);
    while (rs.next()) {
    String s = rs.getString("name");
    out.println(" field values for Name are " + s);
    }
    }
    catch(Exception e){
    out.println("Error " + e);
    }
    --------------------------------------------------
    but when i run the servlet i get folowing exception :
  • java.sql.SQLException: Pool connect failed: java.sql.SQLException: Connection Pool JDBCAccessPool does not exist.

  • --------------------------------------------------
    i have set JDBC Connection pool Driver as :
  • Name : JDBCAccessPool
  • URL : jdbc:weblogic ool
  • DriverClassName : sun.jdbc.odbc.JdbcOdbcDriver:Telephone

  • please help in solving my problem
    20 years ago