Java 如何将用户重定向到预期页面,并在jspservlet中修改详细信息?
我的项目的主要功能是授予用户修改他想要的事件的权限。 因此,第一个页面是modify-event.jsp,他将在其中获得系统中存在的事件列表,并在最后一列显示modify按钮 修改event.jspJava 如何将用户重定向到预期页面,并在jspservlet中修改详细信息?,java,mysql,jsp,servlets,Java,Mysql,Jsp,Servlets,我的项目的主要功能是授予用户修改他想要的事件的权限。 因此,第一个页面是modify-event.jsp,他将在其中获得系统中存在的事件列表,并在最后一列显示modify按钮 修改event.jsp <%@page import="java.util.ArrayList"%> <jsp:include page="includes/header.jsp" /> <div> <%@page import="java.sql.DriverMana
<%@page import="java.util.ArrayList"%>
<jsp:include page="includes/header.jsp" />
<div>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%
HttpSession session1 = request.getSession();
//String id = request.getParameter("userId");
String driverName = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String dbName = "technovision";
String userId = "root";
String password = "root";
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<h2 align="center"><font><strong>Retrieve data from database in jsp</strong></font></h2>
<table align="center" cellpadding="5" cellspacing="5" border="1">
<tr>
</tr>
<tr bgcolor="#A52A2A">
<td><b>Event name</b></td>
<td><b>Registration Amount</b></td>
<td><b>EventHead name</b></td>
<td><b>EventHead contact</b></td>
<td><b>Event Description</b></td>
<td><b>Action</b></td>
</tr>
<%
try{
connection = DriverManager.getConnection(connectionUrl+dbName, userId, password);
statement=connection.createStatement();
String sql ="SELECT * FROM events";
resultSet = statement.executeQuery(sql);
while(resultSet.next()){
session1.setAttribute("eventid",resultSet.getString(1));
session1.setAttribute("eventname",resultSet.getString(2));
session1.setAttribute("registrationamount",resultSet.getString(3));
session1.setAttribute("eventheadname",resultSet.getString(4));
session1.setAttribute("eventheadcontact",resultSet.getString(5));
session1.setAttribute("eventdescription",resultSet.getString(6));
//ArrayList a = new ArrayList();
//a.add(resultSet.getString(1));
//a.add(resultSet.getString(2));
//a.add(resultSet.getString(3));
//a.add(resultSet.getString(4));
//a.add(resultSet.getString(5));
//a.add(resultSet.getString(6));
%>
<tr bgcolor="#DEB887">
<td><%=resultSet.getString("event_name") %></td>
<td><%=resultSet.getString("registration_amount") %></td>
<td><%=resultSet.getString("eventhead_name") %></td>
<td><%=resultSet.getString("eventhead_contact") %></td>
<td><%=resultSet.getString("event_description") %></td>
<td><a href="modify-page.jsp">Modify</a></td>
</tr>
<%
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
</div>
<%@ include file="includes/footer.jsp" %>
<%@include file="includes/scripts.jsp" %>
</body>
</html>
在jsp中从数据库检索数据
事件名称
注册金额
事件头名称
事件头接触
事件描述
行动
现在,当用户单击任何修改按钮时,他应该重定向到页面,该页面将获取单击的事件详细信息,以便他可以编辑相同的内容,但这里的情况是,它在modify-event.jsp中打开上面表中的最后一个数据,因为我使用了httpsession,但我猜是以错误的方式使用的。
所以,当用户单击修改按钮时,我将他重定向到页面名modify-page.jsp
修改page.jsp
<%@page import="java.util.ArrayList"%>
<jsp:include page="includes/header.jsp" />
<%--<%@ page import="com.event"%>--%>
<style>
input.eventdescription{
padding-top : 20px;
padding-bottom : 100px;
}
</style>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Connection"%>
<%
// ArrayList[] eventname = new ArrayList[10];
// ArrayList[] registrationamount = new ArrayList[10];
// ArrayList[] eventheadname = new ArrayList[10];
// ArrayList[] eventheadcontact = new ArrayList[10];
// ArrayList[] eventdescription = new ArrayList[10];
// ArrayList[] eventid = new ArrayList[10];
//
//HttpSession session1 = request.getSession();
// eventname = (ArrayList[])session1.getAttribute("eventname");
// registrationamount = (ArrayList[])session1.getAttribute("registrationamount");
// eventheadname = (ArrayList[])session1.getAttribute("eventheadname");
// eventheadcontact = (ArrayList[])session1.getAttribute("eventheadcontact");
// eventdescription = (ArrayList[])session1.getAttribute("eventdescription");
// eventid = (ArrayList[])session1.getAttribute("eventid");
%>
<div class="addevent-content" style="background-color:black">
<div class="pattern height-resize">
<div class="container">
<form class="form-horizontal" action="UpdateEvent" method="post"
id="addevent_form" >
<!-- Form Name -->
<center>
<h2 id="registerheading">
<b style="color: gold">Modify Event</b>
</h2>
</center>
<br>
<!-- Text input-->
<div class="form-group">
<label class="col-md-5 control-label" style="color: #fff">Event
Name<abbr title="Required">*</abbr>
</label>
<div class="col-md-5 inputGroupContainer">
<div class="input-group">
<input name="event_name" id="form_fname" placeholder="Event Name"
value='${eventname}' class="form-control" type="text" required>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-5 control-label" style="color: #fff">Registration Amount<abbr title="Required">*</abbr>
</label>
<div class="col-md-5 inputGroupContainer">
<div class="input-group">
<input name="registration_amount" id="form_lname" placeholder="Registration Amount"
value='${registrationamount}' class="form-control" type="text" required>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-5 control-label" style="color: #fff">Event Image<abbr
title="Required">*</abbr></label>
<div class="col-md-5 inputGroupContainer">
<div class="input-group">
<input name="event_image" placeholder="Event Image" class="form-control"
value='' type="text" required>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-5 control-label" style="color: #fff">EventHead Name<abbr
title="Required">*</abbr></label>
<div class="col-md-5 inputGroupContainer">
<div class="input-group">
<input name="eventhead_name" id="password1" placeholder="EventHead Name"
value='${eventheadname}' class="form-control" type="text" required>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-5 control-label" style="color: #fff">EventHead Contact
<abbr title="Required">*</abbr>
</label>
<div class="col-md-5 inputGroupContainer">
<div class="input-group">
<input name="eventhead_contact" id="password2" placeholder="(+91)"
value='${eventheadcontact}' class="form-control" type="text" required>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-5 control-label" style="color: #fff">Event Description<abbr
title="Required">*</abbr></label>
<div class="col-md-5 inputGroupContainer">
<div class="input-group">
<input name="event_description" id="email" placeholder=""
value='${eventdescription}' class="form-control eventdescription" type="text" required>
</div>
</div>
</div>
<!-- Select Basic -->
<input name="event_id"class="form-control"
value='${eventid}' type="hidden" >
<!-- Button -->
<div class="form-group">
<label class="col-md-5 control-label"></label>
<div class="col-md-5">
<br>
<button type="submit" class="btn btn-warning">SUBMIT</button>
</div>
</div>
</form>
</div>
<!-- /.container -->
</div>
<!-- pattern height resize-->
</div>
<%@ include file="includes/footer.jsp" %>
<%@include file="includes/scripts.jsp" %>
</body>
</html>
input.eventdescription{
填充顶部:20px;
填充底部:100px;
}
修改事件
事件
名称发送带有url的唯一id
<a href="modify-page.jsp?id=<%=resultSet.getString("eventid") %>">Modify</a>
然后在修改页面中获取idrequest.getParameter(“id”)
将数据库再次连接到
使用eventid=?
sql语句从事件中选择*。发送带有url的唯一id
<a href="modify-page.jsp?id=<%=resultSet.getString("eventid") %>">Modify</a>
然后在修改页面中获取idrequest.getParameter(“id”)
将数据库再次连接到
使用eventid=?sql语句从事件中选择*。我将从头开始。MVC模式。只剩下15天提交最后一年的项目。时间对我来说更少。发送带有url的唯一id。然后在modify page request.getParameter(“id”)中获取id。若你们学习速度慢,学习MVC模式需要cca的一半,最多一天。Google for
JSPServlet mvc模式教程
,如果您喜欢观看而不是阅读,会有很多结果,甚至是一些YT视频。你将受益于学习如何正确地做事,而不是编写大量的意大利面代码。哦,那么我想我应该试一试。你能建议一些链接@JozefChocholacekI从头开始吗。MVC模式。只剩下15天提交最后一年的项目。时间对我来说更少。发送带有url的唯一id。然后在modify page request.getParameter(“id”)中获取id。若你们学习速度慢,学习MVC模式需要cca的一半,最多一天。Google forJSPServlet mvc模式教程
,如果您喜欢观看而不是阅读,会有很多结果,甚至是一些YT视频。你将受益于学习如何正确做事,而不是编写大量的意大利面代码。哦,那么我想我应该试试。你能推荐一些链接@JozefChocholacek吗