0

I'm learning about web development. And I'm using jquery $.get method to fetch data from a server through http GET. here is a snippet of my code

js:

  $.get("servlet.jsp", function(data){
     alert("first name is: "+ data);

jsp:

   <%
    Dao users = new Dao();
    out.println(users.fetchLastName("Jack"));
    %>

where Dao is a java class that fetch last name of first name Jack from a database.

That produced an internal server error. So does this mean that the method fetchLastName has somehow failed to establish connection to the database even though that it works when I run it normally, or is it that I haven't done the correct mapping of the output?

ssayyed
  • 766
  • 1
  • 8
  • 13
  • Does the error occur when you open the url in your browser? – Tilman Schweitzer Feb 07 '14 at 00:37
  • no, url opens with no errors, but when I click the button that fires the request. I can see in the network tab of chrome's developer tool the request was made but error in status. – ssayyed Feb 07 '14 at 00:43
  • 1
    servlet.jsp is a relative url. Is it possible that the path of your page is different from the path of the servlet.jsp? – Tilman Schweitzer Feb 07 '14 at 00:47
  • they are in the same directory. – ssayyed Feb 07 '14 at 00:54
  • Using tomcat webserver, and according to their documentation Java classes should be placed in WEB-INF/classes. so thats where I placed my java class – ssayyed Feb 07 '14 at 00:55
  • could you post the log of the server which will be diplayed on console? – ajitksharma Feb 07 '14 at 04:59
  • **Do not write scriptlets in JSP**, because scriptlets shouldn't be used in JSPs for more than a decade. Learn the JSP [EL](http://stackoverflow.com/tags/el/info), the [JSTL](http://stackoverflow.com/tags/jstl/info), and use servlet for the Java code. See [How to avoid Java Code in JSP-Files?](http://stackoverflow.com/q/3177733/1031945). See [Servlet Ajax answer](http://stackoverflow.com/a/20758729/1031945). Most useful [link](http://stackoverflow.com/q/4112686/1031945) – Aniket Kulkarni Feb 07 '14 at 05:46

0 Answers0