944,052 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 7079
  • Java RSS
Aug 30th, 2005
0

Move out java code from jsp

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Soni_7 is offline Offline
3 posts
since Jul 2005
Aug 30th, 2005
0

Re: Move out java code from jsp

Read up about MVC architectures, JSTL, Servlet controllers, and things like that.
O'Reilly's JSP book is a good start (get the latest 3rd edition).

Don't get suckered into using Struts. It's an overly complex monstrosity, to which there are far better alternatives (the main reason it is still prominent is the fact that it was the first and thus has a large installed base).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: need an answer please
Next Thread in Java Forum Timeline: Please Help!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC