Look my validation code:
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%
Connection connection = null;
ResultSet SQLRetorno = null;
ResultSet SQLRetorno_cons = null;
Statement SQLQuery = null;
String consulta = null;
int erro = 0;
int errado = 0;
int certo = 0;
String erro_str = "erro";
String contador = "";
String user = "";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"

.newInstance();
connection = DriverManager.getConnection("jdbc

dbc:sqlintranet"

;
SQLQuery = connection.createStatement();
String host = request.getRemoteHost();
String remoteuser = request.getRemoteHost();
%>
<%
String consulta_cons="SELECT distinct COUNT(*),loginame,hostname FROM [master].[dbo].[sysprocesses] " +
" WHERE hostname ='" + host + "' group by loginame,hostname";
SQLRetorno_cons = SQLQuery.executeQuery( consulta_cons );
while ( SQLRetorno_cons.next() ) {
contador = SQLRetorno_cons.getString(1);
session.setAttribute("utilizador",SQLRetorno_cons.getString(2));
session.setAttribute("hostname",SQLRetorno_cons.getString(3));
}
%>
<%
if (!contador.equals("0"

){
session.setAttribute("nivel", host);
%>
<INPUT TYPE="hidden" NAME="username" VALUE="<%= user %>">
<INPUT TYPE="hidden" NAME="hostname" VALUE="<%= host %>">
<jsp:forward page="teste/index.jsp">
<jsp

aram name="username" value="<%= user %>" />
</jsp:forward>
<%
}
%>
<%
if (contador.equals("0"

){
%>
<INPUT TYPE="hidden" NAME="username" VALUE="<%= user %>">
<INPUT TYPE="hidden" NAME="hostname" VALUE="<%= host %>">
<jsp:forward page="teste/index1.jsp">
<jsp

aram name="username" value="<%= user %>" />
</jsp:forward>
<%
}
%>
<body>
<CENTER>
</CENTER>
</BODY>
</HTML>