Бьюсь и не могу справиться с простейшим, метод "printText" в классе Class, в сервлете request.setAttribute на JSP, выводит ошибку 500, гляньте код, что не так? Tomcat8, IntelliJ IDEA Ultimate
Class, Servlet:
public class Servlet extends HttpServlet {
public class Print {
public String printText() {
return "Hello!";
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Print p = new Print();
p.printText();
request.setAttribute("p", p);
request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
}
}
JSP:
<html>
<body>
<p>${p.printText}</p>
</body>
</html>
ошибка:
Made changes, but leads to errors
Type Exception Report
Message An exception occurred processing JSP page [/index.jsp] at line [16]
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: An exception occurred processing JSP page [/index.jsp] at line [16]
13: </head>
14: <body>
15: <p>Connect to Server <a href="Servlet"> press</a></p>
16: <p>Message: ${p.printText}</p>
17: </body>
18: </html>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:584)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Servlet.doGet(Servlet.java:19)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
public class Servlet
создан внутренний классPrintText
PrintText p = new PrintText();
объявляете некий объект. Что это за объект что за класс? Есть ли у него методprintText
. Дополните код.