aspose file tools*
The moose likes Java in General and the fly likes jdbcrealms using tomcat and oracle working only when i execute first,next time onworks not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "jdbcrealms using tomcat and oracle working only when i execute first,next time onworks not working" Watch "jdbcrealms using tomcat and oracle working only when i execute first,next time onworks not working" New topic
Author

jdbcrealms using tomcat and oracle working only when i execute first,next time onworks not working

Nazeer Ahammad
Ranch Hand

Joined: Feb 26, 2012
Posts: 43
Hi all,

i was trying to execute jdbcrealms authotication using tomcat and oracle database. When i was running first time it is asking username and password, if i will provide valid user name and password i'm getting home. If i will run next time it is not asking username and password, directly it is giving home page,then i have taken below steps:

1)killing the session even though it not working.
2)i have given session time out in web.xml even though no use
3)i restarted server but no use .

please anyone solve my problem.

Below are the classes and configuration files i have used
index.jsp
---------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Index page

<a href="test">Invoke Generic Servlet</a>
</body>
</html>
----------
web.xml
----------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>JDBCRealmDemo</display-name>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>test.TestServelt</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<security-constraint>
<web-resource-collection>
<web-resource-name>JDBC Realm Example</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>employee</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
-------------
context.xml in META-INF Folder
-------------
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Realm className="org.apache.catalina.realm.JDBCRealm"
connectionName="reuse"
connectionPassword="reuse"
connectionURL="jdbcracle:thin:@blrkec96002d:1521:REUSE"
debug="99"
driverName="oracle.jdbc.driver.OracleDriver"
roleNameCol="role_name"
userCredCol="password"
userNameCol="user_name"
userRoleTable="tomcat_users_roles"
userTable="tomcat_users"/>
</Context>
-------------
TestServelt.java
-------------
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class TestServelt extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
HttpSession session=request.getSession();
PrintWriter out = response.getWriter();
out.println("This is the Test Servlet");}}


Thanks,
Nazeer
 
Don't get me started about those stupid light bulbs.
 
subject: jdbcrealms using tomcat and oracle working only when i execute first,next time onworks not working