简体   繁体   English

在1个Java JSP页面中编辑/删除多个表

[英]Editting/deleting multiple tables in 1 java jsp page

Currently I got the following code: 目前我得到以下代码:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<form method="post" action="update.jsp">
<table border="1">
<tr><th>ID</th><th>Name</th><th>Genre</th><th>Site</th></tr>
<%
String num = request.getParameter("id");
int id = Integer.parseInt(num);
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("sample connection", "sample user", "sample pass");
String query = "select * from table where id='"+id+"'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
%>
<tr>
<td><input type="text" name="id" value="<%=rs.getInt("id")%>"></td>
<td><input type="text" name="naam" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="Genre" value="<%=rs.getString("genre")%>"></td>
<td><input type="text" name="url" value="<%=rs.getString("url")%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<%
}
}
catch(Exception e){}
%>
</table>
</form>

Basically this is the jsp page to update 1 table of my database, however is it possible to make a general jsp page for any table (different amount of columns, different column names etc) or do you have to create a specific jsp page for every single table you have? 基本上,这是用于更新数据库中1个表的jsp页,但是可以为任何表(不同的列数,不同的列名等)创建一个通用的jsp页,还是必须为每个表创建一个特定的jsp页单桌你有吗? Also if it's possible, how would you do it and what would I need? 另外,如果可能,您将如何做?我需要什么? Cause honestly, I have no idea how to start with that. 老实说,我不知道如何开始。

I assume that if it's possible for an edit, that it's also possible for a delete and insert. 我假设如果可以进行编辑,那么也可以进行删除和插入。 (Correct me if I'm wrong) (如果我错了纠正我)

You can create a controller with required methods to process a request to crud each table and make either a jsp page with all tables or a number of pages for every single table. 您可以使用所需方法创建控制器,以处理对每个表进行加粗处理的请求,并创建一个包含所有表的jsp页面或为每个表创建多个页面。

if you could split the view and logic it would make the development process a way more easy and flexible 如果您可以拆分视图和逻辑,则可以使开发过程更轻松,更灵活

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM