We help IT Professionals succeed at work.

How to use getpageContext.RealPath  in a jsp program in Weblogic

dfn48
dfn48 asked
on
The  following jsp program works well in tomcat but i get an error message in weblogic.  The

error that i get in Weblogic is as follows

doc_ss.jsp: 42:13: No method with this name could be found at this location.
String path=getServletContext().getRealPath(“/ns.txt”)
No method with this name could be found at this location,   getRealPath(java.lang.String) in type <error>
String path=getServletContext().getRealPath(“/ns.txt”).  Please tell me what is the correct syntax for Weblogic

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page language="java" import="java.io.* "%>

<!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=UTF-8">
</head>
<body>
<%

String textToTextArea = "";
String path=getServletContext().getRealPath("/ns.txt");
File file = new File(path);
FileReader in = new FileReader(file);
int c;
char ch;
while (( c= in.read()) != -1){
ch=(char)c;
textToTextArea += ch;
}
in.close();

    %>

</td>
</tr>
</table>
<H1>Notification(s):</H1>
    <FORM id="frmnotification" name="frmnotification" action="doc_ss.jsp" method="post">
           <textarea cols="300" rows="30" name="txtnotification" class="txtarea-style"><%=textToTextArea%></textarea>



    </FORM>
    </body>
</html>

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007
Commented:
Try
getServletConfig().getServletContext()
plus your getRealPath call.

It turns out that Weblogic did their servlet implementation slightly differently than Tomcat.  See more explanation here:
http://www.coderanch.com/t/68642/BEA-Weblogic/Bea-Weblogic
rrzstudent
CERTIFIED EXPERT

Commented:
Yes, try mrcoffee's solution.
I don't use Weblogic. But, I wonder, does
String path = application.getRealPath("/ns.txt");
work ?

Author

Commented:
Thanks  very much. Your solution worked well.
CERTIFIED EXPERT
Top Expert 2007

Commented:
Great -- good luck!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.