導航:首頁 > 編程語言 > jsp批量保存數據

jsp批量保存數據

發布時間:2023-03-31 12:58:15

1. jsp表單提交,將內容保存資料庫

<%@ page language="java" contentType="text/html; charset=GB2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>添加好友</title>

</head>
<body bgcolor="ffaaff">
<center><br><br><br><br>
<%

String driverClass="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/friend";
String username = "root";
String password = "root";
Class.forName(driverClass);
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
String id=request.getParameter("id");
String name=request.getParameter("name");

String tel=request.getParameter("tel");
if(id.equals("")|name.equals("")|tel.equals(""))
{
response.sendRedirect("add2.jsp");
}
else{
String sql = "insert into stu(id,name,tel) values('"+id+"','"+name+"','"+tel+"')";
stmt.executeUpdate(sql);
out.print("成功添加好友:");
name=new String(name.getBytes("ISO-8859-1"));
out.print(name);
}
stmt.close();
conn.close();

%>
<a href="admin.jsp"> 返回管理首頁</a>
</center>
</body>
</html>
用javabean做,你要提交表到給這個jsp文件就可以提交,不懂得在回問哈!

2. jsp 批量修改選中的數據,如圖所示,復選框選中幾條數據後,將文本框的值保存到資料庫中去

這些表單項的name屬性按照一定的規律來,
邏輯非常復雜,
但是絕對能實現。
主要的地方在於各個表單項的命名,
給你推薦一個,
比如:第一個行id是1,那麼文本框就叫txt1,復選框叫check1
第二個行id是2,那麼文本框就叫txt2,復選框叫check2
自己做吧,

3. 如何批量保存jsp網頁

你找一個復C語言的爬蟲吧制。
可以參考這個:http://hi..com/qteqpid_pku/item/a09d923c5ff81af2a8842808
將你的生成網址批量的發進去這個工具,然後另存到本地~~

其實更加建議的是你保存下載的內容到資料庫,那麼多的文件內容~

4. 如何將JSP頁面中的表單信息保存到Mysql資料庫

獲取表單中的信息,然後插入到Mysql中
<%@pagelanguage="java"contentType="text/html;charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<%
intid=Integer.parseInt(request.getParameter("id"));
introotid=Integer.parseInt(request.getParameter("rootid"));

%>

<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gbk">
<title>Replay</title>
</head>
<body>
<formmethod="post"action="ReplayOK.jsp">
<inputtype="hidden"name="id"value="<%=id%>">
<inputtype="hidden"name="rootid"value="<%=rootid%>">
<tablealign="center">
<tr>
<td>
<inputtype="text"name="title"size="80">
</td>
</tr>

<tr>
<td>
<textareacols="80"rows="20"name="cont"></textarea>
</td>
</tr>

<tr>
<td>
<inputtype="submit"value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>

---------------------------------------------------------------
下面接收上面表單中傳過來的信息,並插入到mysql中

<%@pagelanguage="java"contentType="text/html;charset=gbk"
pageEncoding="gbk"%>
<%@pageimport="java.sql.*"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<%
request.setCharacterEncoding("GBK");
intid=Integer.parseInt(request.getParameter("id"));
introotid=Integer.parseInt(request.getParameter("rootid"));
Stringtitle=request.getParameter("title");
Stringcont=request.getParameter("cont").replaceAll(" ","<br/>");

Connectionconn=null;
Statementst=null;

Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/bbs?user=root&password=690115399");
st=conn.createStatement();

conn.setAutoCommit(false);

Stringsql="insertintoarticlevalues(null,?,?,?,?,now(),0)";
PreparedStatementpstmt=conn.prepareStatement(sql);
pstmt.setInt(1,id);
pstmt.setInt(2,rootid);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.executeUpdate();

st.executeUpdate("updatearticlesetisleaf=1whereid="+id);

conn.commit();
conn.setAutoCommit(true);

st.close();
pstmt.close();
conn.close();
%>

<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gbk">
<title>Inserttitlehere</title>
</head>
<body>
<%response.sendRedirect("ShowArticleTree.jsp");%>
</body>
</html>
當然最好的方法還是應該用jsp+JavaBean方式。

閱讀全文

與jsp批量保存數據相關的資料

熱點內容
maya粒子表達式教程 瀏覽:84
抖音小視頻如何掛app 瀏覽:283
cad怎麼設置替補文件 瀏覽:790
win10啟動文件是空的 瀏覽:397
jk網站有哪些 瀏覽:134
學編程和3d哪個更好 瀏覽:932
win10移動硬碟文件無法打開 瀏覽:385
文件名是亂碼還刪不掉 瀏覽:643
蘋果鍵盤怎麼打開任務管理器 瀏覽:437
手機桌面文件名字大全 瀏覽:334
tplink默認無線密碼是多少 瀏覽:33
ipaddgm文件 瀏覽:99
lua語言編程用哪個平台 瀏覽:272
政采雲如何導出pdf投標文件 瀏覽:529
php獲取postjson數據 瀏覽:551
javatimetask 瀏覽:16
編程的話要什麼證件 瀏覽:94
錢脈通微信多開 瀏覽:878
中學生學編程哪個培訓機構好 瀏覽:852
榮耀路由TV設置文件共享錯誤 瀏覽:525

友情鏈接