Very urgent: call servlet from JSP

Hello,
I'm facing a problem in invoking a servlet from a JSP having the JSF components.
The application has a text field to implement ajax for search functionality in the database .I have written a servlet to make the database connection and fire the querry.
Ajax implementation in a js file is called on every keyup event in the jsp file,and
a call is given to the servlet from the ajax methode.
The function in the js file is as follows:-
function getPersonByFirstNameXML( firstName ) {
    if (!firstName) {
        clearPersonByFirstNameXML();
    } else {   
        var url = BASE_URL + "/servlet/get_PersonsXML";
        alert(url);
        return new AJAXRequest("post", url, "firstName=" + encode(firstName), processGetPersonByFirstNameXML);
}Im getting the myAJAX.status value as 500.
I think I'm not able to access the servlet properly.
what changes do i need to make in the we.xml file ?
and what should be the url to be passed.
Please provide me a sloution to the above problem as it is very urgent else if anybody is aware of a readymade JSF componet with search functionality freely available please let me know.
PS:
The sample application named RedirectionExample which makes use of a servlet and would be of help to you. You can find the tutorial on the following page:
http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
is not available as stated in some of the suggestions by Author: mayagiri
Thanks for any help.
Abhi

the status 500 generally means either HTTP server internal error or that execution of CGI script or servlet aborted with error.
It can be reasonably supposed that the request reaches the servlet, ie. that "url" value points to some existing servlet, otherwise most probably the status value would be 404.
To test that the servlet is working i'd try to access it using some simple html page with form like this (with {BASE_URL} replaced by real value):
<form method=post action={BASE_URL}/servlet/get_PersonsXML>
<input type=text name=firstName>
<input type=Submit>
</form>

Similar Messages

  • Wot all ways are there to call servlet from jsp

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanx

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanxhi here are few ways... to call servlet from jsp...
    these are just generic syntax.
    Form:     
    <form action="ServletPath">
    Link:     
    Directives & Action tags :
    <%@ page import="ServletPath" %>
         <%@ taglib uri="ServletPth" %>
         <jsp:include page="ServletPath">
         <jsp:forward page="ServletPath">
         <jsp:useBean class="ServletPath"> (Not sure about this useBean)
    hope you got your answer.
    regards,
    immu

  • How to call Servlet from jsp page and how to run this app using tomcat..?

    Hi ,
    I wanted to call servlet from jsp action i.e. on submit button of JSP call LoginServlet.Java file.
    Please tell me how to do this into jsp page..?
    Also i wanted to execute this application using tomcat.
    Please tell me how to do this...? what setting are required for this...? what will be url ..??
    Thanks.

    well....my problem is as follows:
    whenever i type...... http://localhost:8080/appName/
    i am getting 404 error.....it is not calling to login.jsp (default jsp)
    but when i type......http://localhost:8080/appName/login.do........it executes servlet properly.
    Basically this 'login.do' is form action (form action='/login.do').....and i wanted to execute this from login jsp only.(from submit button)
    In short can anyone please tell me how to diaplay jsp page using tomcat 5.5
    plz help me.

  • How to call servlet from jsp

    i m trying to call it from jsp using
    <a href="../purchaseP?orderno=<%=pno%>"><%=pno%></a>
    but its giving error..
    type Status report
    message HTTP method GET is not supported by this URL
    description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

    i m trying to call it from jsp using
    <a href="../purchaseP?orderno=<%=pno%>"><%=pno%></a>
    but its giving error..
    type Status report
    message HTTP method GET is not supported by this URL
    description The specified HTTP method is not allowed
    for the requested resource (HTTP method GET is not
    supported by this URL).Are you implementing the doGet or doPost method in your servlet? If you are calling from a hyperlink then it needs to be implementing the GET method. To access the POST method use a html form.

  • Urgent: how to call servlet from JSP

    I have a working servlet which returns a table in html format. I also updated the web.xml file according to the information I got from the previous message. My problem is how to correctly invoke the servlet in the JSF. I tried the following ways:
    <jsp:include page="/report">
    <jsparams>
    <jsparam name="srcDev" value="#{Page1.srcDevice}"/>
    <jsparam name="tgtDev" value="#{Page1.tarDevice}"/>
    <jsparam name="format" value="complete"/>
    </jsparams>
    </jsp:include>
    and
    <frame src="/report?param1=val1&param2=val2" name="body" frameborder="YES" scrolling="YES" bordercolor="#999999" noresize>
    both doesn't work.I am able to run the servlet within a html form. I just don't know what's the right syntax for calling the servlet inside a JSP page in JSF.
    Can anybody help me?
    Thanks,
    Christine

    Hi Christine,
    This forum is exclusively for Sun Java Studio Creator related issues.
    In case you are using Creator then you can find a sample application named RedirectionExample which makes use of a servlet and would be of help to you. You can find the tutorial on the following page:
    http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
    Cheers
    Giri :-)

  • How to call servlet from jsp in portal applicaton...??

    JDeveloper - 11.1.1.6.0
    Hii all, i am working on an portal application in which i have added my adf application as portlet..
    in this adf application i am having an jsp page on the popup
    the action of this jsp page is set to an servlet
    <form id="form1" action="servlet/UpdateServlet">
    <input type="text" name="test"/>
    <input type="submit" value="SUBMIT"/>
    </form>
    But when i click on submit button, the servlet is not being called..
    The servlet is -
    public class UpdateServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException {
    String value1 = request.getParameter("test");
    System.out.println("one : "+value1);
    Any help on this
    Thanks
    Edited by: 938480 on Oct 3, 2012 1:56 AM

    Which application server you are using.
    I am using JRUN SERVER.
    For me it is very easy
    I have to put my servlet in web-inf/classes/xx.class.
    Then i can run like
    http://localhost/xx.
    Let me know which server u are using.

  • Problem calling servlet from JSP

    Hi All,
    I am running Tomcat 4.1.31 + Apache 2.0.54 for a web app. I have a jsp in a folder in my context root that is calling a servlet. My web.xml looks like this
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE web-app (View Source for full doctype...)>
    - <web-app>
    <display-name>Web Application</display-name>
    - <!-- +===========================================+
    | SERVLET: Controller |
    +===========================================+
    -->
    - <servlet>
    <servlet-name>Controller</servlet-name>
    <description>Testing Servlets</description>
    <servlet-class>servlets.Controller</servlet-class>
    <load-on-startup />
    </servlet>
    - <servlet-mapping>
    <servlet-name>Controller</servlet-name>
    <url-pattern>/Controller</url-pattern>
    </servlet-mapping>
    </web-app>
    and my jsp is as below:
    <form name="loginForm" id="loginForm" action="/Controller" method="post">
    <table border="1" cellpadding="5" width="300">
    <tr>
    <td>User Id </td>
    <td><input type="text" name="userid" size="20" maxlength="15"/></td>
    </tr>
    <tr>
    <td>Password</td>
    <td>
    <input type="password" name="passwd" size="20" maxlength="10"/>
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <input type="submit" name="submit" id="submit" value="Submit"/>
    </td>
    </tr>
    </table>
    <input type="hidden" name="action" id="action" value="login"/>
    </form>
    However, this doesnt work at all. Whenever I hit the submit button I get a 404 File not Found error.
    I have to give the entire url starting with the context root in the JSP for the servlet to work. Is that how it is supposed to work?? I was under the impression that once everything is defined correctly, Tomcat will figure out that the JSP and the servlet belong to the same app and get it from there.
    Can anyone help me please???
    Let me know if anything is not clear enough.
    Thank you!
    amrutaa

    Actually this is just an example app ... but I am going to have other jsps that will call the controller servlet ..
    Thanks a lot for your help. I really appreciate it.
    What stumps me is that the call to the servlet was working day before yesterday and yesterday it just wouldnt!
    and I am sure I touched only the servlet in the meanwhile + restarted Apache as well as Tomcat.
    Thanks again!
    -Amruta

  • C:import tag - Query string while calling servlet from JSP

    Hi,
    From my JSP I am calling a servlet to write back to the response stream of the JSP. From the JSP i am trying to pass some values into the query string as follows
         <%
         String strGetParameters = "/servlet/MyServlet?path=" + strPath;
          %>
         <pre><c:import url="<%=strGetParameters%>" /></pre>In the servlet I try to get the path from the query string by using
    request.getParameter("path")But in the servlet the query string doesnt have the "path" parameter that I added in the strGetParameters string (in the JSP).
    Am i missing something? Do i have to use something else or do something else?
    Any help is appreciated.

    I've taken some time to do a simple test and it just works.
    Here is the test code, it was tested in Java EE 5 + JSTL 1.2 + Tomcat 6.
    JSP<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
    <html>
        <head>
            <title>Test</title>
        </head>
        <body>
            <pre>
                <c:import url="myServlet?param1=foo&param2=bar">
                    <c:param name="param3" value="meep" />
                    <c:param name="param4" value="waah" />
                </c:import>
            </pre>
        </body>
    </html>MyServlet (mapped on "/myServlet")package mypackage;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class MyServlet extends HttpServlet {
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
            String param1 = request.getParameter("param1");
            String param2 = request.getParameter("param2");
            String param3 = request.getParameter("param3");
            String param4 = request.getParameter("param4");
            String output = param1 + ", " + param2 + ", " + param3 + ", " + param4;
            response.getOutputStream().write(output.getBytes());
    }All parameters gets printed.

  • Not able to call servlet from jsp

    I have a jsp from which i'm calling a servlet code is given below:-
    <html>
    <body>
    <jsp:forward page="/doubleHello" />
    </body>
    </html>
    my web.xml is:-
    <web-app>
    <display-name>HelloServlet</display-name>
    <description> HelloServlet </description>
    <servlet>
    <servlet-name> ServletCallingEjb </servlet-name>
    <servlet-class> myServlet.HelloServlet </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name> ServletCallingEjb </servlet-name>
    <url-pattern> /doubleHello </url-pattern>
    </servlet-mapping>
    </web-app>
    My servlet looks like:-
    package myServlet;
    import myEjb.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.*;
    import java.io.PrintWriter;
    import java.io.IOException;
    public class HelloServlet extends HttpServlet
    public void doGet (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
         out.println("<html><head><title>Hello from Servlet</title></head>");
         out.println("<body><h1>Hello from hello servlet!</h1></body>");
    out.println("<br>";
    out.println("</html>");
    But when i run the code i'm getting page cannot be displayed. Please please suggest what am i doing wrong???
    Message was edited by:
    Samrat Kar

    Reframing the question
    I have a jsp from which i'm calling a servlet code is given below:-
    <html>
    <body>
    <jsp:forward page="/doubleHello" />
    </body>
    </html>
    my web.xml is:-
    <web-app>
    <display-name>HelloServlet</display-name>
    <description> HelloServlet </description>
    <servlet>
    <servlet-name> ServletCallingEjb </servlet-name>
    <servlet-class> myServlet.HelloServlet </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name> ServletCallingEjb </servlet-name>
    <url-pattern> /doubleHello </url-pattern>
    </servlet-mapping>
    </web-app>
    My servlet looks like:-
    package myServlet;
    import myEjb.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.*;
    import java.io.PrintWriter;
    import java.io.IOException;
    public class HelloServlet extends HttpServlet
    public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter(); out.println("<html><head><title>Hello from Servlet</title></head>");
    out.println("<body>Hello from hello servlet!</body>");
    out.println("</html>"); } }
    But when i run the code i'm getting page cannot be displayed. Please please suggest what am i doing wrong???

  • How to get an ArrayList Object in servlet from JSP?

    How to get an ArrayList Object in servlet from JSP?
    hi all
    please give the solution for this without using session and application...
    In test1.jsp file
    i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
    After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
    ---------Code----------
    <jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
    <jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
    <%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
    <jsp:setProperty name="payment" property="strDate" param="expirationDate" />
    <jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
    <%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
    <jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
    <jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
    <jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
    <%
    lis.add(payment);
    %>
    </jsp:useBean>
    <%
    request.setAttribute("lis1",lis);
    %>
    -----------Code in JSP-----------------
    In testServlet.java
    i tried to get the arraylist object in servlet using request.getAttribute
    But I unable to get that arrayObject in servlet.....
    So if any one help me out in this, it will be very helpfull to me..
    Thanks in Advance
    Edward

    Hi,
    Im also facing the similar problen
    pls anybody help..
    thax in advance....
    Litty

  • Error in accessing servlet from JSP

    Hello everybody,
    When I access a servlet from a JSP page,I am getting the following error message :
    Error 404--Not Found
    From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
    10.4.5 404 Not Found
    The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
    If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.
    I am using Weblogic 7.0 and my web.xml code is as follows:
    <web-app>
    <servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/TestServlet</url-pattern>
    </servlet-mapping>
    </web-app>
    I am accessing the servlet from a javascript function in my JSP page.
    I am quite new to the Java technology. So any help in this regard would be highly appreciated.
    Thanks in advance,

    The form action event is in a javascript function. I am sorry I mentioned that I am accessing this servlet from JSP. Actually,this servlet is accessed from an HTML document.
    The following is the javascript code:
    <script language="javascript">
    function lfnCallNext()
         alert("In the function");
         frmMain.method="POST";
         frmMain.action="/TestServlet";
         frmMain.hidChoice.value="GetList";
         frmMain.submit();
    </script>
    And this function is called from an hyperlink as follows:
    Work with Employee Database
    Thanks,

  • Calling servlet from a java program

    Hi
    I need to call a servlet's doPost() method from a java program. I have a specific situation, where I need to call servlet from a java program. DUring this call I need to pass a file and two string to the servlet. Servelt after receiving the file and string uploads the file to the server at a specified location. I am stuck up as how to call servlet from a java program instead of a HTML or JSP.
    Can anyone help me to start with this.
    any suggestion is welcome.

    You have to establish a URLConnection with servlet from your java program.
    URL servletURL = new URL("http://localhost:8080/Myservlet?str1=abc&str2=def");
    URLConnection servletConnection = servletURL.openConnection();you can get the objectOutputStream
    ObjectOutputStream oos = new ObjectOutputStream (servletConnection.getOutputStream());
    oos.writeObject(your file object);-------------------------------------------------
    In the servlet u can get the strings using request.getParameter("str1");
    In the servlet u can get the strings using request.getParameter("str2");
    file = new ObjectInputStream (request.getInputStream()).readObject()a lot of resources are available on this ...
    hope this helps :)

  • Calling Servlet from a java prog?

    Hi all,
    I am calling servlet from a java prog (Java Agent in Lotus Notes) by using URL and URLConnection object. how can i trigger the Servlet By using doPost method .I have to send some parameter also.
    Thanx
    Muthu

    you need to open a connection to the servlet. Then you must call getInputStream() and getOutputStream() and use them in any way you see fit. I was trying this before and could not get POST to work unless I openned the input stream from the servlet. Strange... but doGet worked without openning the input stream???
    // open a connection....
    // write to the servlet
    servletConnection.getOutputStream().write("whatever");
    servletConnection.getOutputStream().flush();
    servletConnection.getOutputStream().close();
    // grab what the servlet sends back, required to do a post.
    byte [] in = new byte[100];
    servletConnection.getInputStream().read(in);
    servletConnection.getInputStream().close();

  • Calling JApplet from jsp

    Hi,
    Can any one tell me how to call JApplet from JSP? I am using <jsp:plugin>
    tag but it is not working.

    use the jsp:plugin tag like this in your jsp page..
    <jsp:plugin  type="applet"
         code="appletclsname.class"
         codebase="ourapplets"
         jreversion="1.5"
         width="400px"
         height="200px">
    </jsp:plugin>

  • Calling servlets from main()?

    Hi
    I would like to know that while calling servlets from another class having main(), how can we set the type of request i.e. put, post or get?
    Thanks

    use the method - setRequestMethod( "POST") of HttpURLConnection for setting the method to POST.Similarly for other methods..
    You could find [url http://java.sun.com/developer/JDCTechTips/2004/tt0210.html#2]this useful

Maybe you are looking for

  • SAP XI 2.0 to 3.0 Upgradation

    Hi All Please let me know whether it is possible to upgrade SAP XI 2.0 to 3.0. If Yes, what all componenents from XI 2.0 can be leveraged to 3.0. If No, is it going to be fresh SAP XI 3.0 implementation. Pls let me know if your comments Regards Madha

  • Reference external library movieclip in library with AS3

    Hello, i am able to load at runtime a library asset in flash cs3. i do this by setting up its linkage property and setting its base class. for eg Class: MyButton Base: flash.display.MovieClip then in my document class, say i had com.kofi.InitializeTe

  • Display-me23n

    Hi , I want to g o to  me23n directly after displaying my purchasing document number in output.How to do this. regards Ivneet

  • Fm for Start Date,Middle Date and End Date

    Hi , Is there any Fm which gives first ,middle and last dates of month. please help me out... Thanks in advance for the help, Sandy.

  • Clicking on a link of a YouTube page dosn't download the video

    1. '''Environment''' PC with MS Windows XP SP3 Operating system I use Firefox version 3.6.13 I have added the extensions: - AutoCompletePro 1.11 - Browsing Protection 1.10 - DownloadHelper 4.8.2 - ConvertHelper 2.2 - DownThemAll 2.0 - FireUploader 0.