User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 375,245 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,206 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting

Move out java code from jsp

Join Date: Jul 2005
Posts: 3
Reputation: Soni_7 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Soni_7 Soni_7 is offline Offline
Newbie Poster

Move out java code from jsp

  #1  
Aug 30th, 2005
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:thin202.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
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 4:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC