aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Almost there with debugging Servlet on Tomcat with Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Almost there with debugging Servlet on Tomcat with Eclipse" Watch "Almost there with debugging Servlet on Tomcat with Eclipse" New topic
Author

Almost there with debugging Servlet on Tomcat with Eclipse

Ken Rubin
Ranch Hand

Joined: Mar 08, 2004
Posts: 66
Hello,

I'm trying to debug a simple servlet on Eclipse running under Tomcat. I can get the Servlet to run and stop at the breakpoints, ( can see code) but I can't
see any of the program variable values.
javascript:emoticon('');

Eclipse is Java EE IDE for Web Developers Build id: 20100917-0705. Tomcat is 6.0.30.

I started Tomcat with the following file as recommended by a tutorial:http://www.wikijava.org/wiki/Debugging_a_servlet_with_tomcat_and_Eclipse_tutorial

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
catalina.bat jpda start

The application is launched as http://localhost:8080/formexample/formServlet

The debug session is remote debug with connection type of standard socket attach and connection properties are localhost 8000.

If anyone can tell me why I can't see the variable values, I would be greatly appreciative!!

Thanks,
Ken

Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

I can get the Servlet to run and stop at the breakpoints, ( can see code) but I can't
see any of the program variable values.


Meaning the variables do not appear under the "variables" view ? Is eclipse aware of the source files to the .class that you are debugging ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Ken Rubin
Ranch Hand

Joined: Mar 08, 2004
Posts: 66
Hi Deepak,

"Meaning the variables do not appear under the "variables" view ? Is eclipse aware of the source files to the .class that you are debugging ?"

Eclipse is aware of my source and lets me step through it in debug mode.

The variables appear under the variable (expressions) view, but eclipse is indicating that a String like bio (shown below in code) cannot be resolved to a variable even though I executed the line.

I can see values for some variables like like 'this' and 'arg0'.

I built the code outside of Eclipse and imported the .war file into a project to debug.

Thanks,
Ken







package com.example.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class FormServlet extends HttpServlet {

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
getServletContext().getRequestDispatcher("/WEB-INF/pages/form.jsp").forward(req, resp);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userName = request.getParameter("username");
String password = request.getParameter("password");
String bio = request.getParameter("bio");
String country = request.getParameter("country");
String subscribeForNewsletter = request.getParameter("newsletter");
String receiveMail = request.getParameter("receivemail");
String reveiveNotifications = request.getParameter("receivenotification");

response.setContentType("text/html");

PrintWriter writer = response.getWriter();
writer.write("<h2> You have entered following values </h2>");
writer.write("
");
writer.write("<table>");
startTableRow(writer);
addTableColumn(writer, "username");
addTableColumn(writer, userName);
closeTableRow(writer);

startTableRow(writer);
addTableColumn(writer, "password");
addTableColumn(writer, password);
closeTableRow(writer);

startTableRow(writer);
addTableColumn(writer, "Bio");
addTableColumn(writer, bio);
closeTableRow(writer);

startTableRow(writer);
addTableColumn(writer, "Country");
addTableColumn(writer, country);
closeTableRow(writer);

startTableRow(writer);
addTableColumn(writer, "Subscribe for news letter");
addTableColumn(writer, subscribeForNewsletter);
closeTableRow(writer);

startTableRow(writer);
addTableColumn(writer, "Receive mail from members");
addTableColumn(writer, receiveMail);
closeTableRow(writer);

startTableRow(writer);
addTableColumn(writer, "Receive notification");
addTableColumn(writer, reveiveNotifications);
closeTableRow(writer);

writer.write("</table>");

writer.close();

}

private static void startTableRow(PrintWriter writer) {
writer.write("<tr>");
}

private static void closeTableRow(PrintWriter writer) {
writer.write("</tr>");
}

private static void addTableColumn(PrintWriter writer, String value) {
writer.write("<td> "+ value + "</td>");
}


Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

I recollect coming across this problem, but I do not recollect how I solved it
 
Consider Paul's rocket mass heater.
 
subject: Almost there with debugging Servlet on Tomcat with Eclipse