【问题标题】:jsp getServletContext() errorjsp getServletContext() 错误
【发布时间】:2010-06-03 08:14:23
【问题描述】:

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Murach's Java Servlets and JSP</title>
</head>

<body>
    <%-- import packages and classes needed by the scripts --%>
    <%@ page import="business.*, data.*" %>

    <%
        //get parameters from the request
        String firstName = request.getParameter("firstName");
        String lastName = request.getParameter("lastName");
        String emailAddress = request.getParameter("emailAddress");

        // get the real path for the EmailList.txt file
        ServletContext sc = this.getServletContext();
        String path = sc.getRealPath("/WEB-INF/EmailList.txt");

        // use regular Java objects
        User user = new User(firstName, lastName, emailAddress);
        UserIO.add(user, path);
    %>
    <h1>Thanks for joining our email list</h1>
    <p>Here is the information that you entered: </p>
    <table cellspacing="5" cellpadding="5" border="1">
        <tr>
            <td align="right">First name:</td>
            <td><%= firstName %></td>
        </tr>
        <tr>
            <td align="right">Last name:</td>
            <td><%= lastName %></td>
        </tr>
        <tr>
            <td align="right">Email Address:</td>
            <td><%= emailAddress %></td>
        </tr>
    </table>

    <p>To enter another email address, click on the Back <br />
    button in your browser or the Return button shown <br />
    below.</p>

    <form action="index.jsp" method="post">
        <input type="submit" value="Return" />
    </form>

</body>
</html>

它给了我这个错误页面...

'C:\bea\user_projects\domains\mydomain.\myserver.wlnotdelete\extract\myserver_sample01_WebContent\jsp_servlet__display_email_entry.java'的编译
失败:
C:\bea\user_projects\domains\mydomain.\myserver.wlnotdelete\extract\myserver_sample01_WebContent\jsp_servlet__display_email_entry.java:140: 可能无法解析符号
由于发生错误而发生 /display_email_entry.jsp 第 19 行:
ServletContext sc = this.getServletContext();

完整的编译器错误: C:\bea\user_projects\domains\mydomain.\myserver.wlnotdelete\extract\myserver_sample01_WebContent\jsp_servlet__display_email_entry.java:140: 无法解析符号
符号:方法 getServletContext()
位置:类 jsp_servlet.__display_email_entry
ServletContext sc = this.getServletContext(); //[ /display_email_entry.jsp; Line:19]                                   ^

1 个错误
2010 年 6 月 3 日星期四 15:56:09 CST

有什么提示吗?我真的是 JSP 新手,这是我的第一次学习实践……在 google.com 上找不到……

谢谢!

【问题讨论】:

    标签: jsp servlets weblogic


    【解决方案1】:

    Weblogic 中的 JSP 在 getServletContext 方面的行为与 Tomcat 不同

    替换ServletContext sc = this.getServletContext();

    ServletContext sc = getServletConfig().getServletContext();

    【讨论】:

    • 上一条评论的链接已经失效了
    • 哇,它在 weblogic 上工作了!!! websphere 应用服务器呢?那里也一样吗?
    猜你喜欢
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多