Code in INDEX_MAP.JSP:
Copy Code code as follows:
<%@ page language= "java" pageencoding= "Utf-8"%>
<%@ page contenttype= "Text/html;charset=utf-8"%>
<%
Request.setcharacterencoding ("UTF-8");
Response.setcharacterencoding ("UTF-8");
Response.setcontenttype ("text/html; Charset=utf-8 ");
%>
<body>
<form action= "insert_map.jsp" method= "POST" >
ID: <input type = "Text" name= "id" value= "0"/>
Name: <input type = "text" name= "name" value= "AAA"/> </br>
Voltage rating: <input type = "text" name= "Voltage_level" value= "110kv"/>
Longitude: <input type = "Text" name= "lon" value= "121." />
Latitude: <input type = "text" name= "lat" value= "28." />
</br>
<input type = "Submit" value= "submitted"/>
</form>
</body>
Code for INSERT_MAP.JSP:
Copy Code code as follows:
<%@ page language= "java" import= "java.util.*,java.sql.*" pageencoding= "Utf-8"%>
<%@ page contenttype= "Text/html;charset=utf-8"%>
<%
Request.setcharacterencoding ("UTF-8");
Response.setcharacterencoding ("UTF-8");
Response.setcontenttype ("text/html; Charset=utf-8 ");
%>
<HTML>
<HEAD>
<title>add Message into table </TITLE>
</HEAD>
<BODY>
<%
String id=request.getparameter ("id"); Get from Form
String name=request.getparameter ("name"); Get from Form
String voltage_level=request.getparameter ("Voltage_level"); Get from Form
String Lon=request.getparameter ("Lon"); Get from Form
String lat=request.getparameter ("lat"); Get from Form
Java.util.Date date=new java.util.Date ();
String datetime=new Timestamp (Date.gettime ()). ToString ();
Try
{
/** Connection Database Parameters **/
String drivername = "Com.mysql.jdbc.Driver"; Driver name
String dbuser = "root"; MySQL User name
String dbpasswd = "123456"; MySQL Password
String dbname = "map_db"; Database name
String Connurl = "jdbc:mysql://localhost/" + dbname + "? user=" + Dbuser + "&password=" + dbpasswd;
Class.forName (drivername). newinstance ();
Connection conn = drivermanager.getconnection (Connurl);
Statement stmt = Conn.createstatement ();
Stmt.executequery ("SET NAMES UTF8");
String insert_sql = "INSERT INTO BIANDIANZHAN_POINT_TB VALUES (' + ID +" ', ' "+ name +" ', ' + Voltage_level + "', Geometry Fromtext (' point ("+ Lon +" "+ Lat +")) ";
String query_sql = "SELECT * from BIANDIANZHAN_POINT_TB";
try {
Stmt.execute (Insert_sql);
}catch (Exception e) {
E.printstacktrace ();
}
try {
ResultSet rs = stmt.executequery (query_sql);
while (Rs.next ()) {
%>
Id:<%=rs.getstring ("id")%> </br>
Name: <%=rs.getstring ("name")%> </br>
Voltage rating: <%=rs.getstring ("Voltage_level")%> </br>
Warp Latitude: <%=rs.getstring ("The_geom")%> </br> </br>
<%
}
}catch (Exception e) {
E.printstacktrace ();
}
Rs.close ();
Stmt.close ();
Conn.close ();
}catch (Exception e) {
E.printstacktrace ();
}
%>
</body>
Visit index_map.jsp:
Value of database before submission:
Enter the test values and submit them to the following page:
The changes to the database are as follows:
Can be seen in the above submitted on the page latitude and longitude is garbled, because the The_geom data type is point type, is a geometric data class geometry class of a subclass, there is a specific format, perhaps this particular format can not be recognized by the browser. The solution I'm considering is to peel the THE_GEOM data and get two values and latitude and longitude. This may not be necessary, however, because there is no need to display these two values.
In general, half done, oh, today a great harvest Ah! Very happy!