shishir gupta

Greenhorn
+ Follow
since Apr 30, 2004
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 shishir gupta

I am a j2ee developer with 3 yrs exp. kindly let me know what kind of (j2ee) questions are asked in interviews nowadays (very frequently asked).

thanks
Shishir
19 years ago
I am unable to compile my servlet. if i do not use requestURL() then it compiles. i have set my classpath as
.;D:\java\core\packages;D:\oracle\ora81\jdbc\lib\classes111.zip;d:\JSDK\lib\jsdk.jar;d:\j2ee1.3.1\lib\j2ee.jar;D:\jakarta-tomcat\lib\servlet.jar;D:\jboss-3.2.3\server\default\lib\javax.servlet.jar;

I am getting two errors when i compile this servlet:

D:\jboss-3.2.3\server\default\deploy\cpnm.war\WEB-INF\classes>javac TokenServlet.java
TokenServlet.java:22: cannot resolve symbol
symbol : method getRequestURL ()
location: interface javax.servlet.http.HttpServletRequest
String requestURLSame =req.getRequestURL().toString() + "?token=" +tokenID;
^
TokenServlet.java:23: cannot resolve symbol
symbol : method getRequestURL ()
location: interface javax.servlet.http.HttpServletRequest
String requestURLNew =req.getRequestURL().toString();
^
2 errors

import javax.servlet.http.*;
import java.util.*;
import java.io.*;

public class TokenServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,

IOException {
String tokenID=req.getParameter("tokenID");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><head><title>Tokens</title></head><body> ");

if(tokenID==null) {
Random rand=new Random();
tokenID=Long.toString(rand.nextLong());
out.println("<p> Welcome. A new token "+tokenID + " is now established</p>");
}
else {
out.println("<p> Welcome back. Your token is " +tokenID + ".</p>");
}

String requestURLSame =req.getRequestURL().toString() + "?token=" +tokenID;
String requestURLNew =req.getRequestURL().toString();

out.println("<p> Click <a href=" + requestURLSame + "> here</a> again to cont. browsing with

same identity.</p>");
out.println("<p> Otherwise, click <a href=" + requestURLNew + "></a> again to start with new

identity.</p>");
out.close();

}
}

Facing the same problem when I try to use getServletContextName (), getAttribute(). If I use getValue() my program compiles. I do not know where I am wrong. I am using JDK1.4 beta version, JBoss3.2.3 which supports latest Servlet specification.
Please help.
19 years ago
I am unable to compile my servlet. if i do not use requestURL() then it compiles. i have set my classpath as
.;D:\java\core\packages;D:\oracle\ora81\jdbc\lib\classes111.zip;d:\JSDK\lib\jsdk.jar;d:\j2ee1.3.1\lib\j2ee.jar;D:\jakarta-tomcat\lib\servlet.jar;D:\jboss-3.2.3\server\default\lib\javax.servlet.jar;import javax.servlet.*;

I am getting two errors when i compile this servlet:

D:\jboss-3.2.3\server\default\deploy\cpnm.war\WEB-INF\classes>javac TokenServlet.java
TokenServlet.java:22: cannot resolve symbol
symbol : method getRequestURL ()
location: interface javax.servlet.http.HttpServletRequest
String requestURLSame =req.getRequestURL().toString() + "?token=" +tokenID;
^
TokenServlet.java:23: cannot resolve symbol
symbol : method getRequestURL ()
location: interface javax.servlet.http.HttpServletRequest
String requestURLNew =req.getRequestURL().toString();
^
2 errors

import javax.servlet.http.*;
import java.util.*;
import java.io.*;

public class TokenServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,

IOException {
String tokenID=req.getParameter("tokenID");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><head><title>Tokens</title></head><body> ");

if(tokenID==null) {
Random rand=new Random();
tokenID=Long.toString(rand.nextLong());
out.println("<p> Welcome. A new token "+tokenID + " is now established</p>");
}
else {
out.println("<p> Welcome back. Your token is " +tokenID + ".</p>");
}

String requestURLSame =req.getRequestURL().toString() + "?token=" +tokenID;
String requestURLNew =req.getRequestURL().toString();

out.println("<p> Click <a href=" + requestURLSame + "> here</a> again to cont. browsing with

same identity.</p>");
out.println("<p> Otherwise, click <a href=" + requestURLNew + "></a> again to start with new

identity.</p>");
out.close();

}
}

Facing the same problem when I try to use getServletContextName ()
Please help.
19 years ago
hello Pankaj,

Thanks for your response.
Please let me know which application server you are using to deploy this servlet. I am using JBoss-3.2.3 (latest version). I tried using javax.servlet.jar (in classpath) but facing the same problem.
19 years ago
I am trying to compile this but getting errors:

RDServlet.java:12: cannot resolve symbol
symbol : method getServletContextName ()
location: interface javax.servlet.ServletContext
out.println(sc.getServletContextName());
^
RDServlet.java:13: cannot resolve symbol
symbol : method getServletName ()
location: interface javax.servlet.ServletConfig
out.println(sg.getServletName());
^

Using JBoss-3.2.3 application server which supports Servlets 2.4 specification.



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

public class RDServlet extends GenericServlet {
public void service(ServletRequest req, ServletResponse res) throws ServletException,

IOException {
ServletContext sc=getServletContext();
ServletConfig sg=getServletConfig();
PrintWriter out=res.getWriter();
out.println(sc.getServerInfo());
out.println(sc.getRealPath("/index.html"));
out.println(sc.getServletContextName());
out.println(sg.getServletName());

}
}
19 years ago
here concept of constructor chaining comes in to picture. In main() we are constructing an object of Mobile class. "Mobile n=new Mobile();"

This will invoke the default constructor of Mobile class. Due to constructor chaining super class(Phone) default constructor will be called. It is the object which decides which method to be called. Here object is of Mobile class so showDevice() of Mobile will be called. It will print "Mobile.showDevice, null".
Then Mobile() will be called and it's showDevice() will be called which will print "Mobile.showDevice,Mobile.device". We created an object n of Mobile class which invokes method showDevice() so it will be executed and print "Mobile.showDevice,Mobile.device".

If in case you declare String device as static :

public class Mobile extends Phone {
static String device = "Mobile.device";
void showDevice() {
System.out.print("Mobile.showDevice,"+device+" ");
}
Mobile() {
showDevice();
}
public static void main(String[] args) {
Mobile n = new Mobile();
n.showDevice();
}
}

The output will be as follows
Mobile.showDevice,Mobile.device Mobile.showDevice, Mobile.device Mobile.showDevice, Mobile.device
my folder name is java and it is in c:\
i think you thought "my folder" as my folder name.
19 years ago
when i try to start rmiregistry from my folder it starts with the following statement:

security properties not found. using defaults.
and then when i start my server it gives UnmarshalException.
19 years ago
i do not save my files in \bin folder. i just tested it whether my program runs or not.
now i want to run my program from my folder. i am unable to do so. i tried to set the classpath...
set classpath=%classpath%;.;c:\jdk1.4\lib\classes.zip;.;

pl let me know where i am wrong.
19 years ago
i have my jdk in c:\jdk
if i save my application in c:\jdk\bin folder then it works fine. i have to set classpath so that i can run my application from my folder for eg: c:\rmi\

my classpath settings are:
.;
19 years ago
can you pl tell me how to set this classpath?
19 years ago
i am trying out a simple rmi program from core java. before posting this mail i went through all the messages but couldn't solve the problem.

Interface:

import java.rmi.*;
public interface Product extends Remote {
String getDescription() throws RemoteException;
}
-------------------------
Implementation:

import java.rmi.*;
import java.rmi.server.*;
public class ProductImpl extends UnicastRemoteObject implements Product {
private String name;
public ProductImpl(String n) throws RemoteException{
name=n;
}
public String getDescription() throws RemoteException {
return "I am a " + name + ". Buy me!";
}
}
-------------------------------
Server:

import java.rmi.*;
import java.rmi.server.*;
public class ProductServer{
public static void main(String str[]){
try{
System.out.println("Constructing server implementation");
ProductImpl p1=new ProductImpl("BW Toaster");
ProductImpl p2=new ProductImpl("ZX Oven");
System.out.println("Binding server implementation to registry..");
Naming.rebind("toaster", p1);
Naming.rebind("oven", p2);
System.out.println("waiting for invocations from client..");
}
catch(Exception e) {
e.printStackTrace();
}
}
}
--------------------------
I am just trying server..... I have run rmic and i am running this application on a pc. Jus to test whether we succeeded in registering the remote objects I wrote a simple program.

import java.rmi.*;
import java.rmi.server.*;

public class Showbindings {
public static void main(String s[]) {
try{
String[] bindings=Naming.list("");
for(int i=0;i<bindings.length;i++)
System.out.println(bindings[i]);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
----------------------------
When i run the server, i get this error...

D:\java\rmi>java ProductServer
Constructing server implementation
Binding server implementation to registry..
java.rmi.ServerException: RemoteException occurred in server thread; nested exce
ption is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
java.lang.ClassNotFoundException: ProductImpl_Stub
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
n Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at ProductServer.main(ProductServer.java:12)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex
ception is:
java.lang.ClassNotFoundException: ProductImpl_Stub
... 6 more
Caused by: java.lang.ClassNotFoundException: ProductImpl_Stub
... 6 more
19 years ago
Want to deploy this application on JBoss3.2.3.

Registered the datasource with a JNDI naming service.

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

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class Connect{

String stat="Not connected";
public void init() {
try{
Context ctx=new InitialContext();
if(ctx==null) throw new Exception("no context");

DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/BooksDB");
if(ds!=null) {
Connection con=ds.getConnection();
if(con!=null){
stat="Got connection " +con.toString();
con.close();
}
}
} catch(Exception e) {e.printStackTrace();}
}

public String getStat() {
return stat;
}
}

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

I have put this class file in WEB-INF/classes folder.

In web.xml i made the following entries:

<description>JDBC Test Application </description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/BooksDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


This is the jsp page from which i am trying to test my connection.
------------------------------------------------------

<html>
<head><title> Connection Test </title></head>
<body>
<%
Connect conn=new Connect();
conn.init();
%>
<h3>Connection Result </h3>
<%=conn.getStat() %>
</body>
</html>

when i run this jsp page i get an error "Not connected"
----------------------------------------------------------

javax.naming.NameNotFoundException: No object bound for java:comp/env/jdbc/BooksDB
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:116)
at javax.naming.InitialContext.lookup(Unknown Source)
at example.jdbcExample.Connect.init(Connect.java:15)
at jsp._0002fjsp_0002fconnect_0002ejspconnect_jsp_0._jspService(_0002fjs
p_0002fconnect_0002ejspconnect_jsp_0.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:296)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:369)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:368)
at org.apache.tomcat.core.Handler.service(Handler.java:261)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:356)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:720)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:666)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
n(HttpConnectionHandler.java:194)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:403)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Unknown Source)
--------------------------------------------
19 years ago
Using Tomcat3.1 and JBoss3.2.3. Want to deploy this application on JBoss.

Registered the datasource with a JNDI naming service.

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

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class Connect{

String stat="Not connected";
public void init() {
try{
Context ctx=new InitialContext();
if(ctx==null) throw new Exception("no context");

DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/BooksDB");
if(ds!=null) {
Connection con=ds.getConnection();
if(con!=null){
stat="Got connection " +con.toString();
con.close();
}
}
} catch(Exception e) {e.printStackTrace();}
}

public String getStat() {
return stat;
}
}

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

I have put this class file in WEB-INF/classes folder.

In web.xml i made the following entries:

<description>JDBC Test Application </description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/BooksDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


This is the jsp page from which i am trying to test my connection.
------------------------------------------------------

<html>
<head><title> Connection Test </title></head>
<body>
<%
Connect conn=new Connect();
conn.init();
%>
<h3>Connection Result </h3>
<%=conn.getStat() %>
</body>
</html>

when i run this jsp page i get an error "Not connected"
----------------------------------------------------------

javax.naming.NameNotFoundException: No object bound for java:comp/env/jdbc/BooksDB
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:116)
at javax.naming.InitialContext.lookup(Unknown Source)
at example.jdbcExample.Connect.init(Connect.java:15)
at jsp._0002fjsp_0002fconnect_0002ejspconnect_jsp_0._jspService(_0002fjs
p_0002fconnect_0002ejspconnect_jsp_0.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:296)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:369)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:368)
at org.apache.tomcat.core.Handler.service(Handler.java:261)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:356)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:720)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:666)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
n(HttpConnectionHandler.java:194)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:403)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Unknown Source)
--------------------------------------------
can u pl tell me is there any class path tobe set? all my beans and other class files gets compiled but not this one. i am deploying my application on tomcat3.1 and JBoss3.2.3
19 years ago