Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

DAYANAND BURAMSHETTY

Ranch Hand
+ Follow
since Aug 06, 2001
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 DAYANAND BURAMSHETTY

Hi,
I am sending three files.
If any problem let me know.
If I'm wrong ..correct me
//UserAdminServlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import javax.ejb.FinderException;

public class UserAdminServlet extends HttpServlet{
private HttpSession session = null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void forward(HttpServletRequest req,HttpServletResponse res,String url)
throws ServletException, IOException{
res.setContentType("text/html");
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
rd.forward(req, res);
}

public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{

/**
* (pages) This is for.... IF have 500 records then It display 1,2,3,4,5...10
*
*/
int pages=0;
/* *
* (dVector)This is dummy vector only 50( 0 to 49 or 50 to 99.. ..etc)
* records keep in this Vector and forward to the UserAdmin.jsp
* /
Vector dVector=null;
......
..............
/**
* All records are available in this(userVec)Vector ...everytime I take
* only 50 records from this Vector and stored in dummy Vector.
* contenetController(Write your own object for getting all records)
* is object from this I get all records.
*/
Vector userVec=contentController.getAllUserList();
/**
* Very first time call this servlet at that moment don't think
* about ORDER(Very first time It's NULL then It 1 to 50 records
* taking from userVec and stored in dummyVec and forward to the
* UserAdmin.jsp)
*/
String order=(String)req.getParameter("ORDER");
if(order==null){

dVector=new Vector();
pages=Math.round((dVector.size())/50);
for (Enumeration e = dVector.elements() ,int i=0; e.hasMoreElements(),i++ {
UserTB usertb=(UserTB)e.elementAt(i);
dVector.addElement(usertb);
if(i<50) break;
}
req.setAttribute("USERLIST", dVector);
req.setAttribute("PAGES", ""+pages);
this.forward(req,res,"/UserAdmin.jsp");
} else {
/** This block never excute very first time.
* First time display the (0-49 records) in UserAdmin.jsp and from that page
* we put index like 1,2,3...If click 2 It display the 50 - 99 records in that(UserAdmin.jsp)
* U put <a href="/UserAdminServlet?ORDER=2">2</a> It calls this servlet take the 50(10-99)
* records from userVec and keep into the dummyVector and forward to the UserAdmin.jsp
*/
int orderInt=(int)Integer.parseInt(order);
dVector=new Vector();
pages=Math.round((dVector.size())/50);
for (Enumeration e1 = dVector.elements() ,int i1=(orderInt-1)*50; e1.hasMoreElements(),i1++ {
UserTB usertb=(UserTB)e1.elementAt(i1);
dVector.addElement(usertb);
if(i1<((orderInt)*50)) break;
}
req.setAttribute("USERLIST", dVector);
req.setAttribute("PAGES", ""+pages);
this.forward(req,res,"/UserAdmin.jsp");

}

}//service
}

//UserTB.java
public class UserTB {
private String userName=null;
private String password=null;
...
pulic void setUserName(String userName){
this.userName=userName;
}
public void setPassword(String password){
this.password=password;
}
.....
public String getUserName(){
return userName;
}
public String getPassword(){
return passWord;
}
.....
}

//UserAdmin.jsp

<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page session = "true" %>
<%

userVec=(Vector)request.getAttribute("USERLIST");
int pages=(int)Integer.parseInt((String)request.getAttribute("PAGES"));
%>
<html>
<form NAME="admin" action="" METHOD="POST" >
<table width=100% border="1" cellspacing="2" cellpadding="5" >
<tr>

<th width="20%" class="adminhdr">User Name</th>
.......
</tr>

<%
for( Enumeration e=userVec.elements() ;e.hasMoreElements();i++){
UserTB usertb = null;
String userId=null;
usertb=(UserTB)e.nextElement();
userId=(String)usertb.getUserName();
....
%>
<tr>
<td width="20%" class="admin"> <%=userId%> </td>
</tr>
<%}%>
</table><br>
<%
//Here display index like 1,2,3,4.... if U click 1 it calls the servlet and the servlet take the records(0 -49) from
//servlet and forward to the this page.
for(int i=0;i<pages;i++){
%><a href="/UserAdminServlet?ORDER=<%=(i++)"><%=(i++)%></a>
}
%>
</form>
</body>
</html>
19 years ago
Hi,
U can insert null values........
public ExPK insert(ExTB rcd) {

Connection con=null;
PreparedStatement ps=null;
String strQry=null;
try {
con = getConnection();
strQry = "INSERT INTO SEA_FILE (USERNAME,PASSWROD,MAILID,USERID..... "+
" VALUES (?, ?, ?,?.... )";
ps = dbConnection.prepareStatement(strQry);
ps.setString(1, rcd.getUserName());
ps.setString(2, rcd.getPassword());
if(rcd.getEmailId()==null){
// MAILID IS VARCHAR TYPE IN USER TABLE
// SET NULL VALUE FOR MAILID
ps.setNull(3, java.sql.Types.VARCHAR);
}else{
ps.setString(3,rcd.getEmailId());
}
if ( rcd.getUserId()!=0 ){
//USERID IS INTEGER TYPE IN USER TABLE
// SET NULL(0) VALUE FOR USERID
ps.setNull(4, java.sql.Types.INTEGER);
}else{
ps.setInt(4, rcd.getUserId());
}

}//EOF INSERT
If I'm wrong .. Correct me
public String sqlDateString()
{
//U can get system time
long time= System.currentTimeMillis();
//It 's convert the system time to java.sql.Date
java.sql.Date systemsqldate=new java.sql.Date(time);

// manifulate the date using the this class
SimpleDateFormat formatter = new SimpleDateFormat ("dd-MM-yyyy");

//sqldate convert the java.util.Date because Using java.util.Date and SimpleDateFormat
// we can manifulate
java.util.Date dateString=(java.util.Date)systemsqldate;

String newDate =null;
try{
newDate = formatter.format(dateString);
}catch(Exception e){
e.printStackTrace();
}
return newDate;
}
If I'm wrong ..correct me
Hi,
I think U R using get method(<form method=get> )that'swhy
U see the userid and password.U'll use post method then
U can't see the userid and password.
<form method=post action="">
....
If I'm wrong ..correct me
19 years ago

Hi,
I got same problem solved this way
write value in double(")quotes.

<input type="text" name="newAnswerText" size="75"
value="<%=BeanName.getTextAnswer(qIndex,i)%>" >
19 years ago
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page session = "true" %>
<%

Vector userVec=null;
//userVec getting from servlet(somewhereelse) for diaplaying all the records
userVec=(Vector)request.getAttribute("USERLIST");
%>
<html>
<head>
<title>Testing </title>
</head>

//UserSvc is servlet for adding or deleteting the records from table.
<form NAME="admin" action="/UserSvc" METHOD="POST" >
</table>
<table width=100% border="1" cellspacing="2" cellpadding="5" >
<tr>
<th width="20%" >User ID</th>
<th width="20%" >Full Name</th>
....
</tr>

<%
for( int i=0,Enumeration e=userVec.elements() ;e.hasMoreElements();i++){
//UserTB is accessor class means ... have setXXX() and getXXX() methods........
UserTB usertb = null;
String userId=null;
usertb=(UserTB)e.nextElement();
userId=(String)usertb.getUserId();
String fullName=(String)usertb.getFullName();

String hiddenFieldFullName="fullName"+i;

..
%>
<tr>
<td width="4%">
<input type="checkbox" name="USERID" value=<%=userId%> ></td>
<td width="20%" > <%=userId%> </td>
//If U need this value ...req.getPaarameter("fullNameX");//X=0,1,..or ..4
<input type="Hidden" name="<%=hiddenFieldFullName%>" value=<%=fullName%> > </td>
<td width="20%"> <%=fullName%> </td>
<%}%>
</tr>
</table>
<input type="submit" name="AddNew" value="Add New">
<input type="submit" name="DeleteChecked">
</form>
</body>
</html>
---------------------------------------------------------------------------
//UserSvc servlet file
public class RoleSvcServlet extends HttpServlet{
//Main(service) function

public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{
//This list(userId[]) getting from jsp
String[] userId= req.getParameterValues("USERID");
//This is for adding the new record
String addNew=(String)req.getParameter("AddNew");
if(addNew!=null){
String fullName=null;
String fullNameValue=null;
...
for(int i=0;i<userId.length;i++){
String fullName=null;
String fullNameValue=null;
fullName="fullName"+i;
fullNameValue=req.getParameter(fullName);
...addFunction(userId[i],fullNameValue....);
}

}else{
for(int i=0;i<userId.length;i++){
...deleteFunction(userId[i]);
}
//Ending delete
}
}//service
}
19 years ago
Jsp........File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<script >
function activation(){
for(var i=0;i<document.form1.A.length;i++){
if(document.form1.A[i].checked){
var a=document.form1.A[i].value;
a="/temp/test1.jsp?A="+a;
alert(a);
location.href=a;
}
}
}
</script>
<%
String re= request.getParameter("A");
%>
<form action="/Example" name="form1">
<%
if(re!=null){
if(re.equals("A")){
%>
<select name="as">
<option value="ab">ab</option>
<option value="ac">ac</option>
</select>
<%
}else{
%>
<select name="as">
<option value="bb">bb</option>
<option value="bc">bc</option>
</select>
<%
}
}%>
<body>
<input type=radio name="A" value=A <% if (re!=null) if(re.equals("A")){%> checked <%}%> onclick="activation();">A
<input type=radio name="A" value=B <% if (re!=null) if((re.equals("B"))){%> checked <%}%> onclick="activation();">B
</form>
</body>
</html>

Example ------Servlet----File

public class Example extends HttpServlet{
private HttpSession session = null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void forward(HttpServletRequest req,HttpServletResponse res,String url)
throws ServletException, IOException{
res.setContentType("text/html");
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
rd.forward(req, res);
}

public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{
//(options)select ..name " as " declared in jsp.

String listType=(String)req.getParameter("as");



}//service
}
19 years ago
U have to write session timeout period in the ...\config\mydomain\applications\DefaultWebApp_myserver\WEB-INF\web.xml.
web.xml
-------------
.....

< session-config >
< session-timeout > 54 </session-timeout >
</session-config >

.....

[This message has been edited by DAYANAND BURAMSHETTY (edited August 10, 2001).]
Try to forward the code.I will check in my system.
Hi,
write dubug statement for display the sql query statement
and check.Sometimes we forget to write , like...etc.Then
it gives the error.Try to forward the code.
java.sql.CallableStatement cst1=con.prepareCall("{call Proc_Company_Get(?)}");
cst1.registerOutParameter(1,java.sql.Types.VARBINARY);
...........
//If U need this value.....
byte result[]=cst1.getBytes(1);
String str=new String(result);
System.out.println("result"+str);
....\wlserver6.0sp1\config\mydomain\applications
All jar files keep in this directory.Using this function
U can get the EJBHome.Write another function or add adtional
information in this function for getting remoteObject.

public EJBHome getEJBHome(String jndiName, String ejbClass)
throws javax.naming.NamingException, ClassNotFoundException {

InitialContext initial = (InitialContext)com.modusmedia.seagatewcms.util.AppSvrContext.getEJBInitialContext();
// get enterprise bean
Object objref = initial.lookup(jndiName);
return (EJBHome) PortableRemoteObject.narrow(objref,
Class.forName(ejbClass));
}
[This message has been edited by DAYANAND BURAMSHETTY (edited August 10, 2001).]
[This message has been edited by DAYANAND BURAMSHETTY (edited August 10, 2001).]
19 years ago


Hi,
I am sending three java files.
If any problem let me know.
Dayanand

//UserAdminServlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import javax.ejb.FinderException;

public class UserAdminServlet extends HttpServlet{
private HttpSession session = null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void forward(HttpServletRequest req,HttpServletResponse res,String url)
throws ServletException, IOException{
res.setContentType("text/html");
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
rd.forward(req, res);
}

public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{

/**
* This is for.... IF have 50 records then It display 1,2,3,4,5...
*
*/
int pages=0;
/* *
* This is dummy vector only 10( 1 to 10 or 2 to 20 ..etc)
* records keep in this Vector and forward to the UserAdmin.jsp
* /
Vector dVector=null;
......
..............
/**
* All records are available in this(userVec)Vector ...everytime I take
* only 10 records from this Vector and stored in dummy Vector.
* contenetController(Write your own object for getting all records)
* is object from this I get all records.
*/
Vector userVec=contentController.getAllUserList();
/**
* Very first time call this servlet at that moment don't think
* about ORDER(Very first time It's NULL then It 1 to 10 records
* taking from userVec and stored in dummyVec and forward to the
* UserAdmin.jsp)
*/
String order=(String)req.getParameter("ORDER");
if(order==null){

dVector=new Vector();
pages=Math.round((dVector.size())/10);
for (Enumeration e = dVector.elements() ,int i=0; e.hasMoreElements(),i++ {
UserTB usertb=(UserTB)e.elementAt(i);
dVector.addElement(usertb);
if(i<10) break;
}
req.setAttribute("USERLIST", dVector);
req.setAttribute("PAGES", ""+pages);
this.forward(req,res,"/UserAdmin.jsp");
} else {
/** This block never excute very first time.
* First time display the (0-9 records) in UserAdmin.jsp and from that page
* we put index like 1,2,3...If click 2 It display the 10 - 19 records in that(UserAdmin.jsp)
* U put <a href="/UserAdminServlet?ORDER=2">2</a> It calls this servlet take the 10(10-19)
* records from userVec and keep into the dummyVector and forward to the UserAdmin.jsp
*/
int orderInt=(int)Integer.parseInt(order);
dVector=new Vector();
pages=Math.round((dVector.size())/10);
for (Enumeration e1 = dVector.elements() ,int i1=(orderInt-1)*10; e1.hasMoreElements(),i1++ {
UserTB usertb=(UserTB)e1.elementAt(i1);
dVector.addElement(usertb);
if(i1<((orderInt)*10)) break;
}
req.setAttribute("USERLIST", dVector);
req.setAttribute("PAGES", ""+pages);
this.forward(req,res,"/UserAdmin.jsp");

}

}//service
}

//UserTB.java
public class UserTB {
private String userName=null;
private String password=null;
...
pulic void setUserName(String userName){
this.userName=userName;
}
public void setPassword(String password){
this.password=password;
}
.....
public String getUserName(){
return userName;
}
public String getPassword(){
return passWord;
}
.....
}

//UserAdmin.jsp

<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page session = "true" %>
<%

userVec=(Vector)request.getAttribute("USERLIST");
int pages=(int)Integer.parseInt((String)request.getAttribute("PAGES"));
%>
<html>
<form NAME="admin" action="" METHOD="POST" >
<table width=100% border="1" cellspacing="2" cellpadding="5" >
<tr>

<th width="20%" class="adminhdr">User Name</th>
.......
</tr>

<%
for( Enumeration e=userVec.elements() ;e.hasMoreElements();i++){
UserTB usertb = null;
String userId=null;
usertb=(UserTB)e.nextElement();
userId=(String)usertb.getUserName();
....
%>
<tr>
<td width="20%" class="admin"> <%=userId%> </td>
</tr>
<%}%>
</table><br>
<%
//Here display index like 1,2,3,4.... if U click 1 it calls the servlet and the servlet take the records(1 -10) form
//servlet and forward to the this page.
for(int i=0;i<pages;i++){
%><a href="/UserAdminServlet?ORDER=<%=(i++)"><%=(i++)%></a>
}
%>
</form>
</body>
</html>
19 years ago
U can get the all the records in ASCENDING ORDER FROM DATABASE
NO NEED TO DO IN ANYTHING IN THIS FUNCTION
String sortedBy="address";// fieldNames (Like..CustomerName //,CustomerAddress..
String order="ASC"; // ASC or DESC
String sql = "select * from customer ORDER BY "+ sortedBy + " "+order ;";
Vector v = new Vector();
// Retrieve the sql data into a vector
for(int i=0; i<v.size(); i++)
{
custname = v.elementAt(0);
custaddr = v.elementAt(1);
.......
out.println(custname);
out.println(custaddr);
}
19 years ago
Hi,
rs is the ResultSet object.Actually
rs.getDate() return the java.sql.Date not java.util.Date.
U have to write like this
java.sql.Date resultDate=rs.getDate(2);
// 2 or 1 according your requirement U write.
Even If U get anyproblem write like this
java.sql.Date reultDate=(java.sql.Date)rs.getDate(2);