Java org.apache.jasper.JasperException:处理 JSP 页面 /editinfo.jsp 时发生异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18122530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.apache.jasper.JasperException: An exception occurred processing JSP page /editinfo.jsp
提问by achll
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:
我有这个 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>
When I run it, I get this error:
当我运行它时,我收到此错误:
org.apache.jasper.JasperException: An exception occurred processing JSP page /editinfo.jsp at line 61
org.apache.jasper.JasperException:在第 61 行处理 JSP 页面 /editinfo.jsp 时发生异常
Line 61 is:
第 61 行是:
value="<%=userInfo.getString("email")%>"
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:
我删除了这条线,它工作得很好(但我需要它来获取价值)。当我保留第 61 行并尝试删除它时:
value="<%=userInfo.getString("username")%>"
value="<%=userInfo.getString("用户名")%>"
which is at line 52 of my page, it still doesn't work.
在我页面的第 52 行,它仍然不起作用。
I also replace line 52 to line 61 and it works.
我还将第 52 行替换为第 61 行,并且它有效。
I also get these errors:
我也收到这些错误:
javax.servlet.ServletException: java.sql.SQLException: Column 'email' not found. java.sql.SQLException: Column 'email' not found.
javax.servlet.ServletException:java.sql.SQLException:未找到列“电子邮件”。java.sql.SQLException:未找到列“电子邮件”。
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?
但我 100% 确定我的数据库有一个电子邮件列。此外,当我对数据库的其他列尝试此操作时,它会返回相同的错误。它仅适用于“用户名”列。请帮我。我该如何解决?
回答by user2408578
Try the following way:
尝试以下方式:
value='<%=userInfo.getString("email")%>'
Does that fix the problem? Actually single quotes might cause problems
这能解决问题吗?实际上单引号可能会导致问题
回答by Mohsin Shaikh
the expression tags means <%= ....... >
表达标签的意思是 <%= ....... >
has take semicolon (;)at the end of expression.
表达式末尾有分号(;)。
value='<%= userInfo.getString("email") ; %>'
I hope it will work ,please try this.
我希望它会起作用,请试试这个。
回答by Yitong
Try:
尝试:
value "<%= userInfo.getString("email") %>"
or
或者
value <%= userInfo.getString("email") %>
No ;
when you use the <%= %>
expression.
不,;
当您使用该<%= %>
表达式时。
Also, I think you don't need two =
signs, but only the one inside <%= %>
.
另外,我认为您不需要两个=
标志,而只需要里面的一个<%= %>
。
回答by L VEERAPANDI BCA
<%
<%
String date1 =request.getParameter("firstdate");
String date2 =request.getParameter("seconddate");
SimpleDateFormat dateformat = new SimpleDateFormat ("yyyy.MM.dd");
Date displaydate1=new Date(date1);
Date displaydate2=new Date(date2);
int differenceInDays = (int) ((displaydate2.getTime() - displaydate1.getTime())/(1000*60*60*24));//common method to calculate number of days
out.println("Between " +dateformat.format(displaydate1)+ " and " +dateformat.format(displaydate2)+ " there are " +differenceInDays+ " days");
%>`
%>`
org.apache.jasper.JasperException: An exception occurred processing JSP page /CalculateDate.jsp at line 36
org.apache.jasper.JasperException:在第 36 行处理 JSP 页面 /CalculateDate.jsp 时发生异常
Solve this error...
解决这个错误...
回答by user1373164
since the original error is java.sql.SQLException
forget about JSP errors for now.
因为最初的错误是java.sql.SQLException
暂时忘记 JSP 错误。
Write some tests for UserPhotosDataContext.getUserProfileInfo(userId)
so you can debug the ResultSet.
编写一些测试,UserPhotosDataContext.getUserProfileInfo(userId)
以便您可以调试 ResultSet。
You're sure email
is in the table - are you sure it's in the sql query ?
你确定email
在表中 -你确定它在 sql 查询中吗?
Also, check that you are retrieving the columns from the ResultSet in the order they appear in the ResultSet.
此外,检查您是否按照列在 ResultSet 中出现的顺序从 ResultSet 检索列。
For example, if your ResultSet is:
例如,如果您的 ResultSet 是:
email, username, ...
email, username, ...
then trying to access email
after you have already accessed username
MIGHTnot work.
然后试图访问email
你已经访问后username
MIGHT不工作。
I say MIGHTbecause this is probably specific to whatever database driver you are using - I came across this when using Sybase.
我说可能是因为这可能特定于您使用的任何数据库驱动程序 - 我在使用 Sybase 时遇到了这个问题。