Hi All,
I am new to java/jsp. I have made a jsp page. And i have included the java code in jsp itself using <%,%> tags. Now i want to move the code to java files keeping this as plain jsp. I think i need to use java beans.Can anyone plz let me know how do i go about it.One more thing, the jsp page was generated using a tool which we have.And i included my code inside it according to the way i want. The code selects table name from the dropdown and displays the corresponding columns of the table in the form of checkboxes. When any of the checkboxex is selected it inserts that column in another table.Following is my code
<SCRIPT Language='Javascript' type='text/javascript' src='scripts/tl_main.js'></SCRIPT>
<SCRIPT Language='Javascript' type='text/javascript' src='scripts/tl_validations.js'></SCRIPT>
<SCRIPT Language='Javascript' type='text/javascript' src='scripts/tl_constants.js'></SCRIPT>
<SCRIPT Language='Javascript' type='text/javascript' src='scripts/tl_support.js'></SCRIPT>
<SCRIPT Language='Javascript' type='text/javascript' src='scripts/tl_locale_support.js'></SCRIPT>
<SCRIPT Language='Javascript' type='text/javascript' src='scripts/<%="tl_messages_l10n_"+localeStr+".js"%>'></SCRIPT>
<SCRIPT Language = "JavaScript" type="text/javascript">
</SCRIPT>
<SCRIPT type="text/javascript" language = "JavaScript">
</SCRIPT>
<%@ include file="ExceptionHandler.jsp" %>
</HEAD>
<BODY class="mainbody" onLoad="tl_initialize();showPopup();" onFocus="tl_onFocus();" >
<DIV id="Utility_div" >
<FORM name="Utility" id="Utility" method="post" action="UtilityMasterEvent.do">
<%
String url = "jdbc:oracle:thin:@202.1.120.151:1921:ICUSTODY";
Connection con = DriverManager.getConnection(url,"app03admin","app03adminpwd");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from utility");//+ tableName );
String resStr = request.getParameter("result");
String tableName = request.getParameter("Table_name");
if(resStr == null){
%>
<INPUT type="hidden" id="Event" name="Event" value="">
<TABLE class="formtable" cellspacing="0" cellpadding="0">
<TR class="formrow1" align="left">
<TD class="buffercol"> </TD>
<TD class="formcol">
<TABLE class="detailstablewrapper" cellspacing="0" cellpadding="0">
<TR class="detailswrapperrow">
<TD class="detailswrappercol" align="left">
<TABLE class="detailstable" cellspacing="1" cellpadding="1">
<TR class="detailsrow1" align="left" >
<TD class="detailscol1" colspan="2">
<TABLE class="headertable" cellspacing="0" cellpadding="0">
<TR class="headerrow" align="left">
<TD class="headercol1">
<LABEL ID="Utility_label" class="formlabel"><%= lDisplayFormatter.format(appBundle,formName, "Utility.Utility") %></LABEL>
</TD>
<TD class="headercol2" align="right" > </TD>
</TR>
</TABLE>
</TD>
</TR>
<TR class="frmcontroledit">
<TD class="frmcontroledit" >
<LABEL ID="Table_name_label" class="formcontrollabel"><%= lDisplayFormatter.format(appBundle,formName, "Utility.Table_name") %></LABEL>
</TD>
<TD class="frmcontroledit" colspan="1">
<SELECT id="Table_name" name="Table_name" onChange="return submitMe();">
<% optionValue= lFormatter.format((String)UtilityObj.get("Table_name"),locale) ;%>
<OPTION value=""><%= lDisplayFormatter.format(commonBundle,formName, "DefaultOption") %></OPTION>
<%
String val = null;
while(rs.next()){
val= rs.getString("table_name");
%>
<OPTION value="<%= val%>"><%= val%></OPTION>
<%
}
%>
</SELECT>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<%}
else if (resStr.equals("Y"))
{
Statement stmt1 = con.createStatement();
Statement stmt2 = con.createStatement();
ResultSet rs1 = stmt1.executeQuery("select * from "+ tableName );
ResultSetMetaData rsmd = rs1.getMetaData();
int noOfCols = rsmd.getColumnCount();
UtilityObj.put("txtTname",tableName);
ResultSet rs2 = stmt2.executeQuery("select AUDIT_DATA from CMAPAUDIT where TABLE_NAME ='"+ tableName+"'" );
String auddet = "";
int ind = 0;
int cnt_in = 0;
int cnt_out = 0;
String colkey = "";
String [] colarr = new String[100];
while(rs2.next())
{
auddet = rs2.getString("audit_data");
while(auddet.indexOf(",")!=-1)
{
ind = auddet.indexOf(",");
colkey = auddet.substring(0,ind);
auddet = auddet.substring(ind+1);
colarr[cnt_in]= colkey.trim();
%>
<SCRIPT type="text/javascript" language = "JavaScript">
alert("<%=colarr[cnt_in]%>");
</script>
<%
cnt_in++;
}
cnt_out++;
}
%>
<SCRIPT type="text/javascript" language = "JavaScript">
alert("EXECUTED");
</SCRIPT>
<table class="formtable" cellspacing="0" cellpadding="0">
<%
String strColName ="";
for(int i=1;i<=noOfCols;i++)
{
strColName = rsmd.getColumnName(i);
for(int j=0;j<colarr.length;j++)
{
if( strColName.equals(colarr[j]))
{
%>
<TR><TD><input type="checkbox" id="chkCol" name="chkCol" value ="<%=rsmd.getColumnName(i)%>" checked = true onclick="checkfun(this);"> <%=rsmd.getColumnName(i)%></TD></TR>
<%
}
}
}
%>
</table>
<INPUT type="hidden" id="Event" name="Event" value="">
<TR class="formrow2" align="left">
<TD class="buffercol"> </TD>
<TD class= "formcol">
<TABLE class="eventstable" cellspacing="0" cellpadding="0">
<TR class="eventsrow2">
<TD class="eventscol" align="right">
<IMG src="images/arr_bullet.gif" class="eventimg" align="texttop"><A id="OK_label" name="OK_label" href="#" onClick="javascript:submitForm('OK')" class="linkblue" ><%= lDisplayFormatter.format(appBundle,formName, "Utility.OK") %></A>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<%
rs.close();
rs2.close();
stmt.close();
stmt2.close();
con.close();
}
%>
<input type="hidden" id="txtTname" name="txtTname" value="<%=tableName%>">
<input type="hidden" id="txtcolval" name="txtcolval">
</FORM>
</DIV>
</BODY>
</HTML>
Thanks in advance.
Regards
Soni