I'm successfully using this code.
Set you connection and table name, you will be fine.
try
{
StringTokenizer stk =null;
String st;
String remote_address =request.getRemoteAddr();
String remote_comp =
InetAddress.getByName(request.getRemoteAddr()).toString();
StringBuffer buffer = new StringBuffer();
buffer.append("Request: ");
buffer.append(HttpUtils.getRequestURL(request));
String queryString ="?"+ request.getQueryString();
String sqlStr= "Insert into PHOENIX_ACCESS_LOG (
LOG_TIME,REMOTE_ADDRES,PATH_INFO,HTTP_USER_AGENT,PARAMS,QUERY_STR,
REFFER , IP,E_MAIL)"
+ " VALUES (SYSDATE,?,?,?,?,?,?,?,?)";
Connection conn = connection.getConnection();
PreparedStatement tblstmt = null;
PreparedStatement stmt = null;
tblstmt = conn.prepareStatement( sqlStr );
tblstmt.clearParameters();
// 1 Comp ---------------------------------------------
stk = new StringTokenizer(remote_comp,"/" );
String comp_name = stk.nextToken();
tblstmt.setString(1,comp_name.toUpperCase() );
// 2 Page ----------------------------------
String reffer =(String) request.getHeader("referer");
String stPage =reffer;
{
stPage = HttpUtils.getRequestURL(request).toString();
int index = stPage.indexOf( "/phoenix/");
if ( index >=0) {
stPage = stPage.substring(index+9);
}
}
tblstmt.setString(2, stPage );
// User Agent
tblstmt.setString(3,request.getHeader("User-Agent"));
// Params
Enumeration names = request.getParameterNames();
buffer = new StringBuffer();
if (names.hasMoreElements())
{
int n =0;
while (names.hasMoreElements())
{
String name = (String) names.nextElement();
String[] values = request.getParameterValues(name);
for (int i = 0; i < values.length; ++i)
{
if ( n++ >0 )
{
buffer.append(";");
}
buffer.append(name);
buffer.append("=");
buffer.append(values[i]);
// buffer.append(');
}
}
}
String stParams = buffer.toString();
tblstmt.setString(4,stParams);
// Query String----------------------------------------
tblstmt.setString(5,queryString);
// Reffer ====================
tblstmt.setString(6,reffer);
// IP
tblstmt.setString(7,remote_address);
// E-MAIL
String e_mail = (String) session.getAttribute("e_mail");
tblstmt.setString(8,e_mail);
int i = tblstmt.executeUpdate();
// out.println("<h3>Added :" + i +" </h3>");
}
catch( SQLException e )
{ String err = "<h3>Sql error :" + e +"</h3>";
out.println(err);
log(err);
}
}
-----Original Message-----
From: Vaishali.Shah [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 26, 2002 1:47 AM
To: JSP-INTEREST
Subject: can i get IP-address and computer name of the client?
hi all
i want to know that from which IP-add and computer name my program has
been
used.
how can i do this?
here we have intranet
my jsp will be run from any where
but i want to keep the track of users and computers.
Thanks in advance
Vaishali
Reliance Ind Ltd
A'bad
========================================================================
===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.372 / Virus Database: 207 - Release Date: 6/20/02
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.372 / Virus Database: 207 - Release Date: 6/20/02
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com