I have this jsp code where I am trying to edit information for the user my web page. I am new to jsp programming and I'm experiencing errors. Here is my code:
<%@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>
When I run it, I get this error:
org.apache.jasper.JasperException: An exception occurred processing JSP page /editinfo.jsp at line 61
Line 61 is:
value="<%=userInfo.getString("email")%>"
I remove this line and it works perfectly fine (but I need this to get the value). When I keep line 61 and try to remove this:
value="<%=userInfo.getString("username")%>"
which is at line 52 of my page, it still doesn't work.
I also replace line 52 to line 61 and it works.
I also get these errors:
javax.servlet.ServletException: java.sql.SQLException: Column 'email' not found. java.sql.SQLException: Column 'email' not found.
But I'm 100% sure that my database has an email column. Also, when I try this for the other columns of my database, it gives back the same error. It only works if it is "username" column. Please help me. How do I fix this?