導航:首頁 > 編程語言 > 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批量保存數據相關的資料

熱點內容
cocoapods版本更新 瀏覽:361
國外it大神教你學習如何編程 瀏覽:312
手機存儲應用程序 瀏覽:284
頁面自適應屏幕如何調整代碼數據 瀏覽:681
jsjson工具 瀏覽:299
資料庫中如何備份一張表的數據 瀏覽:739
網路設備能用到什麼 瀏覽:64
暴風轉碼如何添加文件夾 瀏覽:515
延安整合網路營銷有哪些 瀏覽:74
查找word打開過的文件在哪裡 瀏覽:137
b樹java代碼 瀏覽:683
電腦文件存儲 瀏覽:657
蘭州中考徵集志願在哪個網站 瀏覽:215
cs文件上傳下載 瀏覽:244
拷貝文件到根目錄下重命名linux 瀏覽:603
api函數的頭文件 瀏覽:249
華為怎麼綁定迷你編程 瀏覽:215
機構怎麼申請少兒編程考級 瀏覽:495
崑山數控編程哪裡好學 瀏覽:459
jspcfor跳出 瀏覽:65

友情鏈接