我有这个jsp代码,我试图在我的网页上为用户编辑信息。我是 jsp 编程的新手,我遇到了错误。这是我的代码:
<%@page import="DatabaseTransactions.UserPhotosDataContext"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
if (session.getAttribute("id") == null) {
response.sendRedirect(request.getContextPath() + "/sign-in.jsp");
}
int userId = Integer.parseInt(session.getAttribute("id").toString());
ResultSet userInfo = UserPhotosDataContext.getUserProfileInfo(userId);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Information</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="styles.css" rel="stylesheet">
</head>
<body class="bodybg">
<jsp:include page="/navigation.jsp"/>
<% userInfo.next();%>
<div class="boxouter" style="margin-top:50px;">
<h3 class="muted">Edit Information</h3>
<!--- more code here---->
<br><br>
<form id="update-form" method="" action="">
<table style="margin:auto">
<tr>
<!--username-->
<td>
<label>Username <span id="uname-error" class="form-error"></span></label>
<input type="text" title="Use at least 6 characters"
name="username" id="uname"
value="<%=userInfo.getString("username")%>"
placeholder="Username" disabled="true">
</td>
<!--email-->
<td>
<label>Email <span id="email-error" class="form-error"></span></label>
<input type="text"
name="email" id="email"
value="<%=userInfo.getString("email")%>"
placeholder="Email" disabled="true">
</td>
</tr>
<!--- more code here---->
</table>
<center/>
<button class="btn btn-info" onclick="enablefields();" id="enablebtn" style="visibility:visible">Edit Information</button>
<a id="savelink" href="#" style="color:white;">
<button class="btn btn-info" id="savebtn" type="submit" style="visibility:hidden">Save</button>
</a>
<a href="#" style="color:white">
<button class="btn btn-info" id="deactivatebtn" style="visibility:visible">Deactivate Account</button>
</a>
</form>
</div>
</div>
<br><br>
<!--- more code here---->
<script type="text/javascript">
function setValues() {
if ("<%=userInfo.getString("gender")%>" == "Male")
$('select option:contains("Male")').prop('selected',true);
else if ("<%=userInfo.getString("gender")%>" == "Female")
$('select option:contains("Female")').prop('selected',true);
}
window.onload = setValues;
</script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-modal.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-popover.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-modalmanager.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/editinfo.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/holder.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/logout.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-dropdown.js"></script>
</body>
</html>
当我运行它时,我得到这个错误:
org.apache.jasper.JasperException:在第 61 行处理 JSP 页面 /editinfo.jsp 时发生异常
第 61 行是:
value="<%=userInfo.getString("email")%>"
我删除了这条线,它工作得很好(但我需要这个来获得价值)。当我保留第 61 行并尝试删除它时:
value="<%=userInfo.getString("用户名")%>"
这是我页面的第 52 行,它仍然不起作用。
我还将第 52 行替换为第 61 行,它可以工作。
我也收到这些错误:
javax.servlet.ServletException:java.sql.SQLException:找不到列“电子邮件”。java.sql.SQLException:未找到列“电子邮件”。
但我 100% 确定我的数据库有一个电子邮件列。此外,当我对数据库的其他列尝试此操作时,它会返回相同的错误。它仅适用于“用户名”列。请帮我。我该如何解决?