JSP implementation background submission programming code automatic Generator

Source: Internet
Author: User
Tags generator reset trim
Js| Programming | backstage Absrtact: This article mainly aims at having some JSP programming experience and the base of the SQL sentence enthusiasts, this article mainly discusses how to automatically call the database table fields, automatically generate the relevant field code code, the code is to automatically generate dynamic Web site JSP code.

........................

First, preface
A few days ago, to Harbin today Turing Computer school to listen to a teacher told the JSP curriculum, the content is full of interesting, simple collation of the class notes, posted out and share with you, because it is the teacher Zhang's content (that is the copyright Ah!). Here, I'll show you a bone, the rest of the meat (explain the method, thought). I believe the people will realize, will not-hehe, then cultivate it!

Second, the introduction
The current software is not generated automatically, and a line of lines of code is not automatically generated. So why don't we try to generate software automatically? Why not work hard to create a line of code that originally needed handwriting? Here Mr. Zhang provides us with such a train of thought.
1. Can you list the relevant fields in your database?
2, since can be listed, you can selectively put the corresponding field Swich () ... case n:{}?

Third, the program implementation code

1, list all the tables in the database

Try
{
DatabaseMetaData Dbmd = Conn.getmetadata ();

Specify the list of required information
String[] types = {"TABLE"};
RS1 = Dbmd.gettables (null, NULL, "%", types);

while (Rs1.next ())
{
String tablename = rs1.getstring (3);
String Tablecatalog = rs1.getstring (1);
String Tableschema = rs1.getstring (2);
Out.println (tablename+ "<BR>");
}
}
catch (SQLException e)
{
}2, automatic generation of the original need for handwritten JSP code <%
if (Request.getparameter ("tablename")!=null)
{
Sql1= "SELECT * from" +request.getparameter ("tablename");
Rs1=stmt1.executequery (SQL1);
ResultSetMetaData RMT;
RMT = Rs1.getmetadata ();
int columnCount = Rmt.getcolumncount ();
Out.println (columncount+ "<br>");
%>
<form method=post action= "" >
<table border= "1" >
<%
for (int i=2;i<=columncount;i++)//Skip number value starting from 2
{
%>
<tr>
<td><%=rmt.getcolumnname (i). Trim ()%>:</td>//Output field name
<td>
<%
Switch (Rmt.getcolumntype (i))
{
Case 1://char
%>
<input type= "text" Name= "<%=rmt.getcolumnname (i). Trim ()%>" ><BR>
<%
Break
Case 4://int
if (Rmt.getcolumnname (i). Trim (). EndsWith ("_id"))
{
%>
<select name= "<%=rmt.getcolumnname (i). Trim ()%>" >
<option > Aa</option>
</SELECT>
<%
}
Else
{
%>
<input type= "text" Name= "<%=rmt.getcolumnname (i). Trim ()%>" onblur= "Jiancha ()" ><BR>
<%
}
Break
Case 12://vchar
%>
<textarea name= "<%=rmt.getcolumnname (i). Trim ()%>" cols= "rows=" 6 "></textarea>
<%
Break
}
%>
</td>
</tr>
<%
}
%>
<tr>
&LT;TD colspan= "2" >
<input type= "Submit" value= "submitted" >
<input type= "reset" value= "reset" >
</td>
</tr>
</FORM>
<%
}
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.