Elanges waran

Greenhorn
+ Follow
since Dec 13, 2007
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 Elanges waran

Hi All,

I want details about how to handle session tracking using struts 2.0 for following senarios with same user id ;

* Single browser with more than one tab.

* Same browser with seprate instance.

* different borwsers.

* How manage cookies.

I would like to have reference urls and sample application for the above.

Thanks in advance.
[ August 06, 2008: Message edited by: Elanges waran ]
15 years ago
Hi All

I am used netbeans5.5 IDE for my web application. Netbeans contains struts 1.2.9 inbuilt. I want the Information & steps to configure Struts2.0 on Net beans and develop Struts 2.0 applications. Already I have downloaded struts 2.0 jar's zip from http://struts.apache.org/.

This is immediate requirement... Kindly Post your valuable ideas and help to proceed netbeans with struts 2.0.

Thanks in Advance.
Regards,
K.Elanges.
16 years ago
Hi Jay Vas,

My suggestions are avoid this scenario as follows:

* use Hibernate pagination concepts with page by page records showing.

* Also Introduce DB VIEW and module for getting records using HQL.
[Check for this : ]https://coderanch.com/t/218145/ORM/java/hibernate-views]

Give your feedback...
Hi Juan Fernandes,

I think you missed on 1-M table hbm( PhoneNumber.hbm.xml ) with relates 1-1 Table.

Simply put on PhoneNumber.hbm.xml in before </class> tag.

<many-to-one name="User" class="com.visualbuilder.hibernate.User"
cascade="all" >
<column name="user_id" />
</many-to-one>
Hi Jay,

Kindly note this : table="MASTERVIEW" in MaterView.hbm.xml. I missed this attribute...
Hi jay vas,

we can mapping views in hibernate's hbm.xml file. As like model mapping we should be done followings:

* create view on the back end.(I used oracle view in my application)
* create a model for the view as like normal table model.
* Mapping the DBView & view model in .hbm.xml
[Here we should give view name instead of table name on table attribute,
id should be relation column name in view]
* Implement our model (with view) in the Application.

Example :

View in DB :

CREATE OR REPLACE VIEW MASTERVIEW (ITEM_CODE,ITEM_DES,UNIT_PRICE,TAX,VAT)
as Select a.item_code ITEM_CODE, a.item_des ITEM_DES, a.unit_price UNIT_PRICE , b.tax TAX ,b.vat VAT from item_master a inner join tax_master b on a.item_code = b.item_code


MasterView.java :

import java.io.Serializable;
/*
* MasterView.java
*
* Created on January 28, 2008, 3:58 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author elangeswaran
*/
public class MasterView implements Serializable {

/** Creates a new instance of MasterView */
public MasterView() {
}
private String item_code;
private String item_des;
private double unti_price;
private double tax;
private double vat;

public String getItem_code() {
return item_code;
}

public void setItem_code(String item_code) {
this.item_code = item_code;
}

public String getItem_des() {
return item_des;
}

public void setItem_des(String item_des) {
this.item_des = item_des;
}

public double getUnti_price() {
return unti_price;
}

public void setUnti_price(double unti_price) {
this.unti_price = unti_price;
}

public double getTax() {
return tax;
}

public void setTax(double tax) {
this.tax = tax;
}

public double getVat() {
return vat;
}

public void setVat(double vat) {
this.vat = vat;
}
}

Hibenate Mapping file [MasterView.hbm.xml]

<?xml version="1.0" encoding="UTF-8"?>

<!--
Document : MasterView.hbm.xml Created on : January 28, 2008, 10:29 AM
Author : elangeswaran
Description: Purpose of the document follows.
-->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="true" default-lazy="false">

<class name="com.myapp.dao.MasterView" table="">

<class name="MasterView" table="MASTERVIEW" mutable="false">
<id name="item_code" column="ITEN_CODE" type="string"></id>
<property name="item_des" column="ITEM_DES" type = "string"/>
<property name="unti_price" column="SUGGN_TITLE" type = "double" />
<property name="tax" column="TAX" type = "double" />
<property name="vat" column="VAT" type = "double" />
</class>
</hibernate-mapping>

I thing above explaination would be help to use Db View with Hibenate Mapping in j2ee application. If you want more information reply to me..

Regards,
K.Elanges
Dear dhwani,

My suggestions for your problem as follows,

1. copy mysql.jar file on ..\Tomcat_home\..\lib folder

2. Changes your deriver and approach as follow :

Class.forName ("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection
( url, "your_mysgl_login", "your_mysgl_password" );
Statement stmt = con.createStatement ();
ResultSet rs = stmt.executeQuery (query);

I think above idea will help to you...
16 years ago
Hi David O'Meara,

Thanks for your valuable Suggestion & ideas. I used SingleThreadModel implmentation in the above servlet and handle the variables as local in doPost() then I added <%@page isThreadSafe="false"%> om my jsp pages. The session collision problem was fixed.

Thanks,
K.Elanges
16 years ago
Hi All,

I developed a web application using JSP & servlet. I created LoginController servlet to get user name to JSP Forms. If More than 2 user access the same form that time the form data would be mixed between users and also refresh (press F5 Key on the browser)the forms repeatedly the same collision will be occurred. Kindly reply any one to avoid this exception...

The Following code is used for LoginController with Active Directory intergration:

/**
* File Name : Logincontroller.java
* Description : Logincontroller is a servlet that handles request & reponse to
* login.jsp
*/

package controller;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Employee;

import com.sun.security.auth.module.NTSystem;

import dao.impl.LoginDAO;
import dao.impl.ViewSuggestionDAOImpl;

/**
* Servlet implementation class for Servlet: Logincontroller
*
*/
public class Logincontroller extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

/**
*
*/
private static final long serialVersionUID = 1L;

private Employee user;
private Employee emp;
private LoginDAO loginDAO;
private List list;
private Iterator iterator;

private FileInputStream fstream;
private DataInputStream in;
private File file;

private FileInputStream ADstream;
private DataInputStream ADin;
private File ADfile;

private String dept_agent;
private String emp_email;
ViewSuggestionDAOImpl view;
HttpSession session;


/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/

public Logincontroller() {
super();
user = new Employee();
loginDAO = new LoginDAO();
list = new ArrayList();
view = new ViewSuggestionDAOImpl();
} //End of Constructor

/**
* This method handles doGet operation for this servlet
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
} //End Of doGet()

/**
* This method handles doGet operation for this servlet
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{
String filepath = "";
String empId = "";
String totalempid = "";
String[] adminempId = {};

String filePath1 ="";
filePath1 = getServletContext().getRealPath("/properties/dbconnection.properties");

ADfile = new File(filePath1);
ADstream = new FileInputStream(ADfile);
ADin = new DataInputStream(ADstream);
String host ="";
session = request.getSession(true);
/*Session Intialized */
session.setAttribute("empname","");
session.setAttribute("empid","");
session.setAttribute("email","");
session.setAttribute("dept_id","");
session.setAttribute("dept","");
session.setAttribute("dept_email","");
session.setAttribute("depagent","");
session.setAttribute("desig","");
session.setAttribute("eligible","");

String user_name = request.getParameter("username");
String password = request.getParameter("pass");

String AD_username = "";
String AD_pass = "";
String ad = "";

String domain_ext="";
String domain_name="";

while (ADin.available() !=0){
String data = "";
String tot_val = "";

//try{
tot_val = ADin.readLine();
data = tot_val.substring(0,tot_val.indexOf("="));
//}catch (Exception e) {
//}

if(data.equals("host")) {
host = tot_val.substring(tot_val.indexOf("=")+1,tot_val.length());
}
if(data.equals("AD_username")) {
AD_username = tot_val.substring(tot_val.indexOf("=")+1,tot_val.length());
}
if(data.equals("AD_password")) {
AD_pass = tot_val.substring(tot_val.indexOf("=")+1,tot_val.length());
}
if(data.equals("domain_ext")) {
domain_ext = tot_val.substring(tot_val.indexOf("=")+1,tot_val.length());
}
if(data.equals("domain_name")) {
domain_name = tot_val.substring(tot_val.indexOf("=")+1,tot_val.length());
}
if(data.equalsIgnoreCase("AD")) {
ad = tot_val.substring(tot_val.indexOf("=")+1,tot_val.length());
}
}
if(ad.equalsIgnoreCase("YES")){
emp_email = ADLoginAuthentication(host,AD_username,user_name,AD_pass,domain_name, domain_ext);
list = loginDAO.getData(emp_email);
}
else{
list = loginDAO.getData(user_name, password);
}


iterator = list.iterator();
while(iterator.hasNext()) {
user = (Employee) iterator.next();
}
if(list.size() > 0) {
setIntoSession(user);
response.sendRedirect("suggestion/index.jsp");
}
else {
response.sendRedirect("suggestion/invalid.jsp");
}
}catch(Throwable e){
e.printStackTrace();
}finally{
}
} // End of doPost()

/* (non-Java-doc)
* @see String ADLoginAuthentication(String host,String username,String password,String domain_ext)
*/
private String ADLoginAuthentication(String host,String username,String password,String domain_ext) {
String mail = "";
String searchBase;
String searchFilter;

Hashtable ldapEnv = new Hashtable();
NTSystem system = new NTSystem();
String domain = system.getDomain()+"."+domain_ext;
String user =System.getProperty("user.home");
String port="389";
String urlDC="ldap://"+host+":"+port+"/";
String dcList="";
try {
dcList="DC="+domain.replaceAll("\\.",",DC=");
} catch (Exception ex) {
System.err.println("Error in regular expression kit: " + ex.getMessage());
}

ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

ldapEnv.put(Context.SECURITY_AUTHENTICATION,"simple");
ldapEnv.put(Context.SECURITY_PRINCIPAL,username);
ldapEnv.put(Context.SECURITY_CREDENTIALS,password);
ldapEnv.put(Context.PROVIDER_URL, urlDC);

searchBase= dcList;
searchFilter = "(&(objectClass=person)(anr="+username+"))";
String objAttribs[]={"mail"};

try {
// Create an LDAP directory context
LdapContext ctx = new InitialLdapContext(ldapEnv,null);
// Search controls are used to assign the scope of the search and the attributes to be returned
SearchControls srchInfo = new SearchControls();
// We want to browse all of the sub-branches of our directory tree
srchInfo.setSearchScope(SearchControls.SUBTREE_SCOPE);
// Identify the attributes of the objects that we want to return
srchInfo.setReturningAttributes(objAttribs);
int nodirObjects = 0;
// Submit the query to the LDAP directory service and return the results in a NamingEnumeration object
NamingEnumeration dirObjects = ctx.search(searchBase, searchFilter, srchInfo);
// Loop through dirObjects returned by the LDAP query
SearchResult dirObject1 = (SearchResult)dirObjects.next();
while (dirObjects != null && dirObjects.hasMoreElements()) {
SearchResult dirObject = (SearchResult)dirObjects.next();
// Display name and requested attributes to the console
String email = "";
for (int i=0; i<objAttribs.length; i++) {
email = String.valueOf(dirObject.getAttributes().get(objAttribs));
String mail_id = email.substring(email.indexOf(":")+1,email.length()).trim();
if(mail_id.equalsIgnoreCase(username)) {
mail = mail_id;
}
}
// Increment the counter
nodirObjects++;
}
ctx.close();
}
catch (NamingException ex) {
System.err.println("Error during query: " + ex.getMessage());
}
return mail;
}// End of ADLoginAuthentication()




private String ADLoginAuthentication(String host,String Aduser_name,String user_name,String password,String domain_name, String domain_ext) {
String mail = "";
String searchBase;
String searchFilter;

Hashtable ldapEnv = new Hashtable();

String domain = domain_name+"."+domain_ext;
String user = user_name+"@"+domain;
String username = Aduser_name;
String port="389";
String urlDC="ldap://"+host+":"+port+"/";
String dcList="";
try {
dcList="DC="+domain.replaceAll("\\.",",DC=");
} catch (Exception ex) {
System.err.println("Error in regular expression kit: " + ex.getMessage());
}

ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
ldapEnv.put(Context.SECURITY_AUTHENTICATION,"simple");
ldapEnv.put(Context.SECURITY_PRINCIPAL,username);
ldapEnv.put(Context.SECURITY_CREDENTIALS,password);
ldapEnv.put(Context.PROVIDER_URL, urlDC);

searchBase= dcList;
searchFilter = "(&(objectClass=person)(anr="+user_name+"))";
String objAttribs[]={"mail"};

try {
// Create an LDAP directory context
LdapContext ctx = new InitialLdapContext(ldapEnv,null);
// Search controls are used to assign the scope of the search and the attributes to be returned
SearchControls srchInfo = new SearchControls();
// We want to browse all of the sub-branches of our directory tree
srchInfo.setSearchScope(SearchControls.SUBTREE_SCOPE);
// Identify the attributes of the objects that we want to return
srchInfo.setReturningAttributes(objAttribs);
int nodirObjects = 0;
// Submit the query to the LDAP directory service and return the results in a NamingEnumeration object
NamingEnumeration dirObjects = ctx.search(searchBase, searchFilter, srchInfo);
// Loop through dirObjects returned by the LDAP query
//SearchResult dirObject = (SearchResult)dirObjects.next();
while (dirObjects != null && dirObjects.hasMoreElements()) {
SearchResult dirObject = (SearchResult)dirObjects.next();
// Display name and requested attributes to the console
String email = "";
for (int i=0; i<objAttribs.length; i++) {
email = String.valueOf(dirObject.getAttributes().get(objAttribs));
String mail_id = email.substring(email.indexOf(":")+1,email.length()).trim();
if(mail_id.equalsIgnoreCase(user)) {
mail = mail_id;
}
}
// Increment the counter
nodirObjects++;
}
ctx.close();
}
catch (NamingException ex) {
System.err.println("Error during query: " + ex.getMessage());
}
return mail;
}
/**
*
* @param user
* setIntoSession() is a synchronized methos to set all necessary
* values in to the session for entire appliation
*
*/
public synchronized void setIntoSession(Employee user){
try {
session.setAttribute("empname",user.getEmpName());
session.setAttribute("empid",user.getEmpId());
session.setAttribute("email",user.getEmp_email());

session.setAttribute("dept_id",user.getDepartment_id());
session.setAttribute("dept",user.getDepartment());

dept_agent = view.findByDepartment(user.getDepartment());


List emp_list = view.findByID(dept_agent);
Iterator iterate = emp_list.iterator();
while(iterate.hasNext()) {
emp = (Employee)iterate.next();
session.setAttribute("dept_email",emp.getEmp_email());
}

if(user.getImd_super_id()==null){
session.setAttribute("imdsuper",emp.getEmpName());
session.setAttribute("imd_super_id",dept_agent);
session.setAttribute("imd_super_email", emp.getEmp_email());
}
else {
session.setAttribute("imdsuper",user.getImmediateSupervisor());
session.setAttribute("imd_super_id",user.getImd_super_id());
session.setAttribute("imd_super_email", user.getImd_super_email());
}

session.setAttribute("depagent",dept_agent);
session.setAttribute("desig",user.getDesignation());
session.setAttribute("eligible",user.getRole());

String filepath = getServletContext().getRealPath("/properties/role.properties");

file = new File(filepath);
FileInputStream fstream = new FileInputStream(file);
DataInputStream in = new DataInputStream(fstream);
while (in.available() !=0){
String empId = in.readLine();
String totalempid = empId.substring(empId.indexOf(":")+1,empId.length());
String [] adminempId = totalempid.split(",");
for(String empid : adminempId){
if(empid.equals(user.getEmpId())) {
session.setAttribute("role","Admin");
break;
}
else {
session.setAttribute("role","Not Admin");
}
}
}
session.setAttribute("date",user.getDateOfJoin());
session.setAttribute("user",user.getEmpName());
}catch(Exception e){
System.err.println("-- Exception in setIntoSession() -->> "+e);

}
}
}

From the above servlet, i used the session setAttributed values on the forms.
16 years ago
Hi All,

I developed a web application used hibernate with Jsp and servlet . also I used a hibernateUtil for ORM to Database. In my application i used on servlet
HttpSession session = request.getSession(); and in Session session = HibernateUtil.getNewSession() for execute our sql query. I want a clarification between httpseession and hibernate session. Kindly Reply in soon..

Thanks,
K.Elanges
16 years ago
Dear Bear Bibeault,

Ok. Thanks....
16 years ago
Hi All,

I used tomcat server for my web application, i used server's IP address like http://192.168.0.62:8080/SampleApp/serach.jsp it is properly woking. but I used as localhost on server system as follows http://localhost:8080/ SampleApp/search.jsp and not properly as functionality wise. Any once clarify regarding difference between server ip address & server's local host.

I am expect the valuable reply.

16 years ago
Hi All,

I used tomcat server for my web application, i used server's IP address like http://192.168.0.62:8080/SampleApp/serach.jsp it is properly woking. but I used as localhost on server system as follows http://localhost:8080/ SampleApp/search.jsp and not properly as functionality wise. Any once clarify regarding difference between server ip address & server's local host.

I am expect the valuable reply.

16 years ago
Hi Jan Cumps,

I want the code sample for AD Integration with Tomcat. I referred some websites , on that they used realm in server.xml. But i want to know how it is implement on our tomcat and how to test with application authentication.

I want your valuable reply in soon....
16 years ago
Hi Jan Cumps,

I want the code sample for AD Integration with Tomcat. I referred some websites , on that they used realm in server.xml. But i want to know how it is implement on our tomcat and how to test with application authentication.

I want your valuable reply in soon....
16 years ago