Home > Back-end >  Using the data in the JSP ku
Using the data in the JSP ku

Time:12-04



Figure is a problem, and then input number is figure 2, figure 3 it is to deal with receiving the number of figure 2, and handle to FIG. 4 the tag, the tag after return to figure 3 of JSP, check for many times, always is the tag back to have a problem? Am lost, can not see the problem by themselves,

CodePudding user response:

The enclosed code:
InputCondition. JSP
<% @ page contentType="text/HTML. Charset=gb2312 "% & gt;
<body bgcolor=pink> According to the student number query

Enter the student id: & lt; Input type="text name=" number "& gt;

According to the fuzzy query name

Name contains & lt; Input type="text name=" name "size=5 & gt;

CodePudding user response:

ByNumber. JSP
<% @ page contentType="text/HTML. Charset=gb2312 "% & gt;
<% @ taglib tagdir="/WEB - INF/tags" prefix="look" % & gt;
<body bgcolor=cyan> <% String number=request. The getParameter (" number "); %>

According to the student id & lt; % %=number & gt; Records of the query to the

<% %=queryResultByNumber & gt;

CodePudding user response:

NumberCondition. The tag
<% % @ tag pageEncoding="gb2312" & gt;
<% @ tag import="Java. SQL. *" % & gt;
<% @ attribute name="number" of required="true" % & gt;
<% @ variable name - "=" queryResultByNumber scope "=" AT the END - "% & gt;
<% StringBuffer result;
Result=new StringBuffer ();
Try {class.forname (". Com. Mysql. JDBC Driver ");
}
The catch (Exception e) {
}
The Connection con;
The Statement SQL;
The ResultSet rs;
Int n=0;
Try {result. Append (" & lt; The table border=1 & gt;" );
String uri="JDBC: mysql://127.0.0.1/Student";
String user="root";
String password="BXL123";
Con=DriverManager. GetConnection (uri, user, password);
DatabaseMetaData metadata=https://bbs.csdn.net/topics/con.getMetaData ();
The ResultSet rs1=metadata. GetColumns (null, null, "message", null);
Int field number=0;
Result. Append (" & lt; Tr>" );
While (rs1. Next ()) {
Field number + +;
String clumnName=rs1. Get String (4);
Result. Append (" & lt; Td>" + clumnName + "& lt;/td>" );
}
Result. Append (" & lt;/tr>" );
SQL=con. CreateStatement ();
String condition="SELECT * FROM the message Where number='" + number +"' ";
Rs=SQL. ExecuteQuery (condition);
While (rs), next ()) {
Result. Append (" & lt; Tr>" );
for(int k=1; K<=number of fields; K++)
Result. Append (" & lt; Td>" + rs. Get string (k) + "& lt;/td>" );
Result. Append (" & lt;/tr>" );
}
Result. Append (" & lt;/table>" );
Con. The close ();
}
The catch (SQLException e) {
Result. Append (" ");
}
JspContext. SetAttribute (" queryResultByNumber ", new String (result);
%>
  • Related