jsp getServletContext () ошибка - PullRequest
       8

jsp getServletContext () ошибка

4 голосов
/ 03 июня 2010

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 \ домены \ MYDOMAIN \ myserver.wlnotdelete \ Экстракт \ 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; Строка: 19] ^

1 ошибка
Чт 03 июня 15:56:09 CST 2010

есть подсказка? Я действительно новичок в JSP, и это моя первая учебная практика ... не могу найти ее по google.com ....

спасибо!

1 Ответ

15 голосов
/ 03 июня 2010

JSP в Weblogic ведут себя иначе, чем Tomcat, в отношении getServletContext

Заменить ServletContext sc = this.getServletContext();

до ServletContext sc = getServletConfig().getServletContext();

...