When I write out.println()
, eclipse complains that out cannot be resolved.
I have imported java.io.*
and other servlet packages.
When I write out.println()
, eclipse complains that out cannot be resolved.
I have imported java.io.*
and other servlet packages.
Just a shot in the dark, I think this is the out
you are looking for:
public class OutServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("foo");
}
}
You should write System.out.println();
inside a function.
If you write it directly into the class then it might show the error that you are having right now.
Import it using a static
import:
import static java.lang.System.out;
However, I'd recommend that you don't do this.
Using the full name makes references to System.out
stand out, and makes them easier to "grep" for ... if you need to nuke traceprints.
If you need to write a lot of stuff to the console, you should make out
a variable or a method parameter. This will help to make your code more reusable; e.g. so that it can write to somewhere other than System.out
.
I had this problem. I found out I didn't have main method( public static void main(string[]args) and that is why it was giving me this error. Hope this helps.
If your are looking to put some debug outputs, you can do this:
System.out.println("foo");
If your are looking for adding the output to HTML not printing on debug console you can do as follow: First you should add the 'servlet-api.jar' to your project. Then simply you can use this if you want to add your output to HTML:
response.getWriter().println("foo");
I hope it helps.
Can you please check whether you are having any class name as "System" ?
This could be one reason.
Like in the code below if I use class name as System it would end up with the same Error like yours.
Cannot use Identifier 'System' as Class name;
public class System {
public static void main(String[] args) {
int A[] = { 3, 9, 7, 8, 12, 6, 15, 5, 4, 10 };
for (int x : A) {
System.out.print(x + ", ");
}
System.out.println("\n*******************");
int t = A[A.length - 1];
System.out.println(t);
}
}