Abhijit Rai

Ranch Hand
+ Follow
since Aug 07, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Abhijit Rai

Hi,
I am trying to explore Java in depth regarding implementation details in Java :
"How are classes such as linked list,Stack,Array ,HashMap ,HashTable are implemented ,which data structures are used ,which memory is used ,how does java interact with the OS and the like ".
Please do flood me with links , resources or books which could help me in getting to the bottom of these issues.
Cheers.
15 years ago
Hi all,

I have a website containing top secret "eyes only " stuff,so to protect its contents I use java authentication.
I am able to authenticate the user properly and every thing works fine.
Where I am stuck is logging out a user once the user is authenticated.
I believe that the problem is in web browser caching and have tried a few things which did not work .
My top military general is annoyed as hell and I would be his Basset Hound 's dinner if the issue is not solved.
Here is the code listing :

web.xml


ControllerServlet1:



sec.jsp


home.jsp


The problem might be because the request being sent by my browser contains a Principal with the corresponding username and password . I dont want to go the java script way and am trying for a complete java solution.

Thanks for having a peek

15 years ago


You are totally wrong


kindly do explain ...
15 years ago
JSP
Hi,
You could invalidate the session in the login.jsp page itself ,this could be done by
<%
if(session!=null)
session.invalidate();
%>
HTH
15 years ago
JSP
Hey Cameron,
Thanks mate ,awesome reply ,was like a beautiful sun ray tearing the dark clouds away .
The link was quite useful too . Just as you did I added a main method in my Cabin class and it works like a charm .


Also the Hibernate configuration xml looks like :


Thanks again , Cheers
Hi ,
I am of the view that JPA may be used for standalone applications (i.e. even without a server(web/application)),
dragged along by this belief I ventured along to make an application

I made an entity class :Cabin


and a client class: StandaloneClient



also I have persistence.xml within META-INF in my classpath




and all I get is a Fat exception :


Is it possible to use JPA the way I want to use it . If yes ,how do we get over this exception( does any one have the postal address for the Persistence provider ) .
Thanks everyone for helping out
Hi,
To access any database Using JDBC follow these steps :
1.Make sure the RDBMS server is up and running correctly.
2.Find out on which port the RDBMS server is .
3.Make sure that the relevant JDBC driver (for you RDBMS ) is present and in class path.

Once these steps are followed write a Java class to access the DB. The steps to be followed in the Class are:

1.Register the JDBC driver for your RDBMS
2.Define URL of database server for your database on the localhost with the relevant port number( default :3306)
save it in a String .

3.Get a connection to the database.

4.Get a Statement object eg:

5.Execute commands on that statement object.

6.Get a ResultSet back

7. Close everything:

Below is a sample ,I am using mySQL database named javatest,



HTH
Hi Mark,


When you set up a JDBC datasource on an application server, at least in my experience, you must give a JNDI name to that datasource.


Clarification:
You can access a database with the JDBC API without using JNDI ,but yes when it comes to datasource you have to use some naming service,I too have used JNDI.
As for the question ,
There are many reasons that according to the specification, one should also specify the <resource-ref> in web.xml. One of the most important reasons is the scope of the DataSource being used.

<resource-ref>
. . .
<res-sharing-scope>Shareable</res-sharing-scope>
. . .
</resource-ref>

You can read more about that in the following thread

https://coderanch.com/forums/posts/watch/0/159428
15 years ago


Ulf Dittmer:
So if you've enjoyed using the Roundup in the past, this is your chance to give back a little to make it even better...


Any place we could drop questions for the new RoundUp Version
Although it is fine to leave a method blank ,it may be useful if you declare the method inside an interface and implement that interface in your class as blank method.
This way it would be clear that the method was meant to be implemented as a blank method rather than it being left blank by mistake .
15 years ago
An add on issue ,
I am trying to make the HelloUser interface Local ie

@Local
public interface HelloUser {
public void sayHello(String name);
}

I also changed jndi.properties to

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099
jnp.localAddress=jnp://localhost:1099
jnp.localPort=1099

The excepiton I get is :

javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Unresolved address [Root exception is java.net.SocketException: Unresolved address] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.UnknownHostException: jnp://localhost:1099: jnp://localhost:1099]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.ejb3inaction.actionbazaar.HelloUserClient.main(HelloUserClient.java:17)
Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.UnknownHostException: jnp://localhost:1099: jnp://localhost:1099]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)
... 4 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.UnknownHostException: jnp://localhost:1099: jnp://localhost:1099]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:248)
... 5 more
Caused by: java.net.UnknownHostException: jnp://localhost:1099: jnp://localhost:1099



What changes should be done (I guess to jndi.properties)to access the bean locally ?

Thanks all for helping out .

Thanks a lot guys ,
Got it working now with your help .As you pointed out the trouble was that I did not have jndi.properties in classpath .

So the working solution can be listed as :

Step 1.
Create "HelloUser.java"
package com.ejb3inaction.actionbazaar;
import javax.ejb.Remote;
@Remote
public interface HelloUser {
public void sayHello(String name);
}



Step 2.
Create "HelloUserBean.java"
package com.ejb3inaction.actionbazaar;
import javax.ejb.Stateless;
@Stateless
public class HelloUserBean implements HelloUser {
public void sayHello(String name) {
System.out.println("Hello " + name + " welcome to EJB 3 In Action!");
}
}


Step3.
Created a client class "HelloUserClient"

package com.ejb3inaction.actionbazaar.client;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.ejb3inaction.actionbazaar.buslogic.HelloUser;
import com.ejb3inaction.actionbazaar.buslogic.HelloUserBean;

public class HelloUserClient {
private static HelloUser helloUser;
public static void main(String[] args) {
try {
Context context = new InitialContext();
helloUser = (HelloUser) context.lookup(“HelloUserBean/remote");
helloUser.sayHello("Obama ");
} catch (NamingException e) {
e.printStackTrace();
}
}
}

Step 4.
Create jndi.properties in the souce folder (src folder)

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099


Step 5.
Deploy the code ,start the server and run the client as a standalone java application.

PS:
Don’t forget to include jBossall-client.jar ,without it ClassNotFound exception is thrown .

thanks and cheers
Couldnt find it there mate am searching the net for it .
Hi could you provide some additional info :
1.Whether the project is a web application deployed on the server or a standalone java apllication
2.In case of it being a web application ,the directory structure of the application , present in the server where it is deployed.
15 years ago
Ernest rightly pointed out that there is no semi colon instruction .My description was intended to help figure out what exactly is happening logically .I have erred on the technical part though .For better understanding of the language I would suggest that you go through any good Java book ,find them at find here - list of beginers java books.
HTH
15 years ago