web.xml`
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringMVCLoginFormValidate</display-name>
<welcome-file-list>
<welcome-file>LoginForm.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>`
spring-servlet.xml`
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.hr.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages" />
</bean>
</beans>
`
LoginForm.jsp
`
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
<style>
.error {
color: red; font-weight: bold;
}
</style>
</head>
<body>
<div align="center">
<h2>Spring MVC Form Validation Demo - Login Form</h2>
<table border="0" width="90%">
<form:form action="login" commandName="userForm" method="post">
<tr>
<td align="left" width="20%">Email: </td>
<td align="left" width="40%"><form:input path="email" size="30"/></td>
<td align="left"><form:errors path="email" cssClass="error"/></td>
</tr>
<tr>
<td>Password: </td>
<td><form:password path="password" size="30"/></td>
<td><form:errors path="password" cssClass="error"/></td>
</tr>
<tr>
<td></td>
<td align="center"><input type="submit" value="Login"/></td>
<td></td>
</tr>
</form:form>
</table>
</div>
</body>
</html>
`
LoginController.java
package com.hr.controller;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.hr.model.User;
@Controller
public class LoginController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String viewLogin(Map<String, Object> model) {
User user = new User();
model.put("userForm", user);
return "LoginForm";
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String doLogin( @ModelAttribute("userForm") User userForm,
BindingResult result, Map<String, Object> model) {
if (result.hasErrors()) {
return "LoginForm";
}
return "LoginSuccess";
}
}
LoginSuccess.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome</title>
</head>
<body>
<div align="center">
<h2>Welcome ${userForm.email}! You have logged in successfully.</h2>
</div>
</body>
</html>
User.java
package com.hr.model;
import org.hibernate.validator.Email;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Size;
public class User {
@NotEmpty
@Email
private String email;
@NotEmpty(message = "Please enter your password.")
@Size(min = 6, max = 15, message = "Your password must between 6 and 15 characters")
private String password;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
am getting the error while debugging as
I had added all the jar files of spring 4.2.5 and Hibernate jars
how to solve the error???
HTTP Status 500 - An exception occurred processing JSP page /LoginForm.jsp at line 21
type Exception report
message An exception occurred processing JSP page /LoginForm.jsp at line 21
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /LoginForm.jsp at line 21
18: <div align="center">
19: <h2>Spring MVC Form Validation Demo - Login Form</h2>
20: <table border="0" width="90%">
21: <form:form action="login" commandName="userForm" method="post">
22: <tr>
23: <td align="left" width="20%">Email: </td>
24: <td align="left" width="40%"><form:input path="email" size="30"/></td>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.lang.IllegalStateException: No WebApplicationContext found: not in a DispatcherServlet request and no ContextLoaderListener registered?
org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:235)
org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:74)
org.springframework.web.servlet.support.JspAwareRequestContext.<init>(JspAwareRequestContext.java:48)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
org.apache.jsp.LoginForm_jsp._jspService(LoginForm_jsp.java:107)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.37 logs.
Apache Tomcat/7.0.37
I am attempting to return the count of mysql rows. I get the following error when I run the .jsp file:
org.apache.jasper.JasperException: An exception occurred processing
JSP page /index.jsp at line 54
Which is this line of code:
// count posts in category 1
catCount = conn.countCategoryPosts(1);
I know the database connection is setup fine.
This is the countCategoryPosts
method.
public int countCategoryPosts(int ncatID) throws Exception{
int catID = ncatID;
try{
sql = "SELECT COUNT(*) FROM crm_posts WHERE cat_id = ?";
prep = conn.prepareStatement(sql);
prep.setInt(1, catID);
rs = prep.executeQuery();
}catch(Exception e){
e.printStackTrace();
}
return rs.getInt(1);
}
What is causing the error?
EDIT: As requested the full stacktrace:
type Exception report
message An exception occurred processing JSP page /index.jsp at line 54
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 54
51: id = Integer.parseInt(catAttributes[1]);
52:
53: // count posts in this category
54: catCount = conn.countCategoryPosts(1);
55:
56: // get posts in this category
57: postList = conn.getCategoryPosts(id);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
root cause
javax.servlet.ServletException: java.sql.SQLException: Before start of result set
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
org.apache.jsp.index_jsp._jspService(index_jsp.java:208)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
root cause
java.sql.SQLException: Before start of result set
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:850)
com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2705)
com.servlet.explore.dbCon.countCategoryPosts(dbCon.java:103)
org.apache.jsp.index_jsp._jspService(index_jsp.java:145)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
geniusis 1 / 1 / 0 Регистрация: 12.06.2019 Сообщений: 7 |
||||||||
1 |
||||||||
11.11.2020, 02:48. Показов 1181. Ответов 2 Метки jsp, sql, tomcat (Все метки)
Добрый день, ошибка в передачи атрибутов в jsp странницу((
И сама ошибка Кликните здесь для просмотра всего текста Type Exception Report Message Unable to compile class for JSP: Description The server encountered an unexpected condition that prevented it from fulfilling the request. Exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [16] in the jsp file: [/view.jsp] An error occurred at line: [18] in the jsp file: [/view.jsp] Stacktrace: Долблюсь уже 2 дня, не понимаю в чем ошибка(
0 |
3638 / 2970 / 918 Регистрация: 05.07.2013 Сообщений: 14,220 |
|
11.11.2020, 08:57 |
2 |
request.getAttribute видимо это возвращает Object, кастани в нужный класс
0 |
geniusis 1 / 1 / 0 Регистрация: 12.06.2019 Сообщений: 7 |
||||
11.11.2020, 12:11 [ТС] |
3 |
|||
Пробовал(( Кликните здесь для просмотра всего текста Type Exception Report Message Произошла ошибка при обработке [/view.jsp] в строке [16] Description The server encountered an unexpected condition that prevented it from fulfilling the request. Exception org.apache.jasper.JasperException: Произошла ошибка при обработке [/view.jsp] в строке [16] 13: //int y = request.getAttribute(«y_atr»); Stacktrace: java.lang.NullPointerException Добавлено через 26 минут
Нужно было эту строчку воткнуть ((
0 |
After installing the update, confluence stopped starting. Writes error 500. confluence on our own server. windows server 2016 + MS SQL help me please
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Произошла ошибка при обработке [errors.jsp] в строке [13]
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: Произошла ошибка при обработке [errors.jsp] в строке [13]
10: <link rel="shortcut icon" href="johnson/fav-confluence.ico">
11: <%
12: JohnsonPageI18NProvider johnsonPageI18NProvider = (JohnsonPageI18NProvider) BootstrapUtils.getBootstrapContext().getBean("johnsonPageI18NProvider");
13: String translations = johnsonPageI18NProvider.getTranslations().serialize();
14: %>
15: <script>
16: window.i18n = <%=translations%>;
Stacktrace:
........................
У меня есть этот код 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: обработано исключение Страница JSP/editinfo.jsp в строке 61
Строка 61:
value = «<% = userInfo.getString(» электронная почта «)% > »
Я удаляю эту строку, и она отлично работает (но мне нужно это, чтобы получить значение). Когда я держу строку 61 и пытаюсь удалить это:
value = «<% = userInfo.getString(» имя пользователя «)% > »
который находится в строке 52 моей страницы, он все равно не работает.
Я также заменю строку 52 на строку 61, и она работает.
Я также получаю следующие ошибки:
javax.servlet.ServletException: java.sql.SQLException: столбец «email» не найден. java.sql.SQLException: не найден адрес электронной почты столбца.
Но я на 100% уверен, что в моей базе данных есть столбец электронной почты. Кроме того, когда я пытаюсь это сделать для других столбцов моей базы данных, он возвращает ту же ошибку. Он работает только в том случае, если это столбец «имя пользователя». Пожалуйста, помогите мне. Как это исправить?