Results 1 to 3 of 3
  1. #1
    frankjava1 is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default How to call method in servet by using JSP?

    can anybody give me example code to call the data from servlet class and view using presentation layer JSP...

    If i created servlet called showservlet.java which it have the connection and query statement to select the data from database (select * from abc). How i call it by view it using JSP..view.jsp.

  2. #2
    zoomix is offline Member
    Join Date
    Oct 2008
    Location
    Sweden, Gothenburg
    Posts
    21
    Rep Power
    0

    Default

    Try thinking of the JSP as an ordinary java class with super-powers. How would you call a method in another class?

    First you would have to import that class. In java you would type:
    import se.frank.com.ShowServlet;

    In a JSP, you type:
    <%@ page import="se.frank.com.ShowServlet" %>


    After that it's as simple as
    <%= ShowServlet.getSuffFromDatabase() %>
    to print whatever ShowServlet.getStuffFromDatabase() returns.

    Mind you, the class ShowServlet is not actually treated as a servlet here. I'm sort of assuming you are misusing the word 'servlet' here as there is generally no reason for mixing servlets and jsp pages.

  3. #3
    frankjava1 is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default

    Thnz Zoomix i'll try it..... if got any problem i ask u back...

Similar Threads

  1. [SOLVED] Call method from another class name
    By antgaudi in forum New To Java
    Replies: 3
    Last Post: 10-15-2008, 01:33 AM
  2. Need to dynamicaly get all parameters in a method call.
    By DavidJohns in forum Advanced Java
    Replies: 2
    Last Post: 05-21-2008, 08:15 AM
  3. Call Java Method
    By hussainzim in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-15-2008, 08:22 AM
  4. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 09:37 AM
  5. Call a Method Automatically
    By rhm54 in forum New To Java
    Replies: 4
    Last Post: 02-07-2008, 09:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •