•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 383,414 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,736 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
Views: 2389 | Replies: 1
![]() |
| |
•
•
Join Date: Jul 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,609
Reputation:
Rep Power: 18
Solved Threads: 188
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).
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).
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
access activation api blogger blogging blogs code com combo dani daniweb data debugging development dreamweaver dropdownlist gdata google gpl html innovation java key linux microsoft microsoft sdk for java microsystems module net news open openbsd platform product programming reuse rss serial software source sun tags vista web wysiwyg xml
- null check of resultset (JSP)
- Auto generate Java Code from WSDL using Axis (Java)
- Executing Shell script from Java code. (Java)
- download jar files using java code (Java)
- I want to know about the java code. Help please!!!! (Java)
- Help with Java code (Java)
- Can N E 1 Help!!!! -- Need sample Java code (Java)
- java code newbie (Java)
Other Threads in the Java Forum
- Previous Thread: need an answer please
- Next Thread: Please Help!!!



Hybrid Mode