hi partha,
my problem is not like this,calling get and post methods of servlets from jsps are working.
this is not my problem.my problem is calling other than get,post methods.
i am sending some sample code.
Servlet1.java
-------------------
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class Servlet1 extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
PrintWriter out=res.getWriter();
out.println("Hello this is Servlet1.....");
getServletConfig().getServletContext().setAttribute("add",this);
}
public int add(int a,int b){
return a+b;
}
}
Servlet2.java
------------------
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class Servlet2 extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
PrintWriter out=res.getWriter();
out.println("Hello i am Servlet2...");
Servlet1 s=(Servlet1)(getServletConfig().getServletContext().getAttribute("add"));
int a=s.add(4,5);
out.println("the result is:"+a);
}
}
these 2 are working fine.2nd servlet displaying the result.
insteadof 2nd servlet i want jsp.
plz. help me for this.
thanks in advance
shiva.
Partharanjan Das <partharanjan.d@SONATA-SOFTWARE.COM> wrote:
Hi,
There are two ways of calling a servelt method from a jsp:
1. for any public method on the servlet, you can call getServlet() from
the JSP for any servlet within the same container specifying the name of the
servlet as specified in the web.xml. This will however bypass the http call
interposition that is done by the container and you are responsible for any
synchronisation or any call interposition requirement. Not recommended.
2. You can make a URLConnection to the servlet from your JSP and call
doGet() or doPost(). The logic should be there in these two methods.
Of course, you can use request dispatcher for mundane uses.
Hope this helps.
Regards,
Partha
----------
From: Sireesha Beeram [SMTP:sireesha_beeram@HOTMAIL.COM]
Sent: Wednesday, June 16, 2004 4:29 PM
To: SERVLET-INTEREST@JAVA.SUN.COM
Subje
ct: Re:
communicate servlet from jsp
To send the call to the servlet page:
1.In your jsp page, put
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
___________________________________________________________________________
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html