日期:2014-05-17  浏览次数:20704 次

求助!jsp代码有错。。。
代码:
<%@ Page contentType="text/html" pageEncoding="GBK" %>
<%@ Page import="java.util.*"%>
<html>
<head><title>我的网页myweb</title></head>
<body>
<%
PageContext.setAttribute("name",王某某);
%>
<%
String username=(String)PageContext.getAttribute("name");
%>
姓名:<%=username%>
</body>
</html>
报错:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /jsp/page_demo1.jsp(1,5) Invalid directive
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:473)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1749)
org.apache.jasper.compiler.Parser.parse(Parser.java:127)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:120)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:180)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.

------解决方案--------------------
Java code

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <base href="<%=basePath%>">
        <title>My JSP 'MyJsp.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
    </head>

    <body>
        <%
            pageContext.setAttribute("name", "王某某");
        %>
        <%
            String username = (String) pageContext.getAttribute("name");
        %>
        姓名:<%=username%>
    </body>
</html>

------解决方案--------------------
探讨

引用: