JSP Questions
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Baskaran_Samundeeswari
Posted On:   Wednesday, July 7, 2010 12:01 AM

testing I want to validate the text field of JSP using some algorithmic functions that also be i writing in JSP. whenever i run that code the browser displays the HTTP Server Internal Error. My Coding is shown below. Anybody please findout what error is there? testing.jsp ----------- <%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> Enter ID No : testing1.jsp ------------ <%@page language="java" contentType="text/html   More>>
testing

I want to validate the text field of JSP using some algorithmic functions that also be i writing in JSP. whenever i run that code the browser displays the HTTP Server Internal Error. My Coding is shown below. Anybody please findout what error is there?

testing.jsp
-----------

			


<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>








Enter ID No :










testing1.jsp
------------


<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" isErrorPage="true"%>



testing1




<%!

public String CheckNRIC(String nric)
{
int nriclength=nric.length();
String fchar=nric.substring(0,1);
String lchar=nric.substring(8,9);
String mchars=nric.substring(1,nriclength-1);
boolean inputbag=isCharsinBag(fchar);
boolean numbercheck=isNumeric(mchars);
boolean alphacheck=isAlphabetic(lchar);
// Check The NRIC Is Not Null
if(nric=="")
return "";
// Check The First Character of NRIC is X
if(fchar=="X")
return "";
// Check The First Character Either 'F','T','S'or 'G'
try{
if(!inputbag)
return "";
}
catch(Exception e)
{
String str=e.toString();
return str;
}
// Check The Middle Characters Are Numeric
try{
if(!numbercheck)
return "";
}
catch(Exception e)
{
return e.toString();
}
// Check 9th Char is alphabetic
try{
if(!alphacheck)
return "";
}
catch(Exception e)
{
return e.toString();
}
// Check 1st Char is 'S' or 'T'
if(fchar=="S"||fchar=="T")
{
String remainder=checkUIN(nric);
String NRIC_Chk_Digit=UinTable(remainder);
if(NRIC_Chk_Digit==lchar)
return "UIN";
}
// Check 1st Char is 'F' or 'G'
if(fchar=="F"||fchar=="G")
{
String remainder1=checkFIN(nric);
String NRIC_Chk_Dig1=FinTable(remainder1);
if(NRIC_Chk_Dig1==lchar)
return "FIN";
}
return "Invalid ID";
}

public String FinTable(String checksum)
{
int sumdigit=Integer.parseInt(checksum);
String alphacode="JZIHGFEDCBA";
String finchar=alphacode.substring(sumdigit);
return finchar;
}

public String UinTable(String checksum1)
{
int sumdigit1=Integer.parseInt(checksum1);
String alphacode1="XWUTRQPNMLK";
String uinchar=alphacode1.substring(sumdigit1);
return uinchar;
}

public boolean isNumeric(String input)
{
for (int i = 0; i < input.length(); i++)
{
if (!Character.isDigit(input.charAt(i)))
return false;
}
return true;
}

public boolean isAlphabetic(String input)
{
int code=Integer.parseInt(input);
if(!((code > 96 && code <123) || (code > 64 && code <91)))
{
return false;
}
return true;
}

public boolean isCharsinBag(String input)
{
String bag="SFTG";
for(int i=0;i <4;i++)
{
if(bag.substring(i)==input)
return true;
}
return false;
}

public String checkUIN(String uin)
{
int a1[]=new int[10];
int i,uin1=0;
int uinlength=uin.length();
String fchar1=uin.substring(0,1);
//String lchar1=uin.substring(8,9);
String mchars1=uin.substring(1,uinlength-1);
int num[]={2,7,6,5,4,3,2};
for(i=0;i <7;i++)
{
String mchar1=mchars1.substring(i,i+1);
a1[i]=Integer.parseInt(mchar1);
uin1+=a1[i]*num[i];
}
if(fchar1=="T")
{
uin1=uin1+4;
//int uin2=uin1/11;
//int uin3=11-(uin1%11);
int remainder=uin1%11;
String a11=new Integer(remainder).toString();
return a11;
}
if(fchar1=="S")
{
uin1=uin1+4;
//int uin2=uin1/11;
// int uin3=11-(uin1%11);
int remainder=uin1%11;
String a11=new Integer(remainder).toString();
return a11;
}
return "";
}

public String checkFIN(String fin)
{
int a2[]=new int[10];
int i,fin1=0;
int finlength=fin.length();
String fchar2=fin.substring(0,1);
//String lchar2=fin.substring(8,9);
String mchars2=fin.substring(1,finlength-1);
int num2[]={2,7,6,5,4,3,2};
for(i=0;i <7;i++)
{
String mchar2=mchars2.substring(i,i+1);
a2[i]=Integer.parseInt(mchar2);
fin1+=a2[i]*num2[i];
}
if(fchar2=="G")
{
fin1=fin1+4;
//int fin2=fin1/11;
//int fin3=11-(fin1%11);
int remainder=fin1%11;
String a1= new Integer(remainder).toString();
return a1;
}
if(fchar2=="F")
{
fin1=fin1+4;
//int fin2=fin1/11;
//int fin3=11-(fin1%11);
int remainder=fin1%11;
String a1=new Integer(remainder).toString();
return a1;
}
return "";
}

%>






testing2.jsp
------------


<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@include file="testing1.jsp"%>


testing2




<%
String nricno=request.getParameter("idno");
out.println("ID No is "+nricno);
String idvalid=CheckNRIC(nricno);
out.println("Given ID is "+idvalid);
%>



   <<Less
About | Sitemap | Contact