扩展页面指令不起作用 [英] extends page directive not working

查看:95
本文介绍了扩展页面指令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查页面指令,但扩展页面指令不起作用.
下面我的jsp页面

Hi i am checking page directives but extends page directive is not working.
The below my jsp page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page extends="javapackage.TestClass" %>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>Hai
<% out.println(show()); %>
</body>
</html>

我的课是

package javapackage;

public class TestClass {
  public String show(){
      return "Welcome Prasad";
 }
}


它给了我500错误


it gives me 500 error
exception

org.apache.jasper.JasperException: java.lang.ClassCastException: org.apache.jsp.first_jsp cannot be cast to javax.servlet.Servlet
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:177)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
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)

root cause 

  java.lang.ClassCastException: org.apache.jsp.first_jsp cannot be cast to javax.servlet.Servlet
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
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)


我甚至尝试过扩展HttpServlet的类,但是没有用.所以任何人都可以帮助我.我正在使用Tomcat 7
谢谢


even i tried with class which extends HttpServlet but of no use .So any one please help me.I am using Tomcat 7
Thanks

推荐答案

您需要阅读JSP规范,特别是JSP.11.2.4节,其中规定了您对与extends一起使用的超类的一些要求,而没有任何要求.您的问题中的超级班级会满足.

You need to read the JSP specification, particularly section JSP.11.2.4 which sets out a number of requirements for the super class you use with extends and none of which are met by the super class in your question.

...提供的超类:

...the provided superclass:

  • 如果协议是HTTP,则实现HttpJspPage,否则,则实现JspPage.
  • Servlet接口中的所有方法都声明为final.

此外,JSP页面作者的责任是提供 超类满足:

Additionally, it is the responsibility of the JSP page author that the provided superclass satisfies:

  • servlet API的service方法调用_jspService方法.
  • init(ServletConfig)方法存储配置,使其可通过以下方式使用 getServletConfig,然后调用jspInit.
  • destroy方法调用jspDestroy.
  • The service method of the servlet API invokes the _jspService method.
  • The init(ServletConfig) method stores the configuration, makes it available via getServletConfig, then invokes jspInit.
  • The destroy method invokes jspDestroy.

这篇关于扩展页面指令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆