Calling servlet in jsp

hello everybody,
i would like to develop a small wepapplication use servlets&jsp
.when i set an attribute in servlet that i need call to my index.jsp
i wrote <%=(String)request.getAttribute("username")%>
am getting null value.Please help how i get value...
Thanks in advance...

Do you set the attribute in the servlet?
Does the request from the servlet is redirected to the jsp?
Manuel Leiria

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.

  • Can`t call Servlet form JSP in JDev 3.1.1.2

    Even after correctly registering a servlet with "Web Object Manager", I can`t access it as an form action on JSP page, running latter from within JDeveloper (famous "Web-to-go URL not found" message).
    Exactly the same configuration works for the old JDeveloper 3.1. There is no mentions in doc about any change here.
    Is there any workaround or patch?

    TooMuchConfusionException
    If you have a class to be called from the JSP, place it in WEB-INF/classes directory under your web app directory... not in the lib directory.
    I wonder how you manage to work on EJB...
    ***Annie***

  • 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.

  • 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>

  • 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???

  • Calling Servlets in JSP forms

    Hello,
    I'm trying to invoke in a html form (jsp file) a servlet, something like this:
    <form method="POST" ACTION="validateLogin" ONSUBMIT="return ValidateForm(this)">
    but the browser returns me this:
    WTG-10109: Web-to-go could not locate requested URL
    Web-to-go could not locate requested URL /validateLogin
    the only way i have to run the servlet is replacing the ACTION field in form by:
    ACTION="MyProj/_servlet_"
    How can i change this?
    regards,
    Miguel

    Hello,
    I'm trying to invoke in a html form (jsp file) a servlet, something like this:
    <form method="POST" ACTION="validateLogin" ONSUBMIT="return ValidateForm(this)">
    but the browser returns me this:
    WTG-10109: Web-to-go could not locate requested URL
    Web-to-go could not locate requested URL /validateLogin
    the only way i have to run the servlet is replacing the ACTION field in form by:
    ACTION="MyProj/_servlet_"
    How can i change this?
    regards,
    Miguel

  • Servlet and JSP combination and design issue

    My task is to generate the list box dynamically based on the input XML file.
    I create a JSP page and a servlet.
    http://www.myserver.com/page1.jsp
    In page1.jsp, I have the following to call servlet from JSP page
    <jsp:include page="myproj.TableGeneration"/>
    In my case, I think I don't need servlet at all, but just Java Bean
    class to generate the table. And JSP page call that Java Bean class.
    But in what situation we need the combination of servlet and JSP?
    What do you think? Any ideas? Thanks!

    Trying to keep the data separate from the view is always a good idea
    I have used XML in a similar way - the XML is the data, this is read and it is uses to populate various page beans - the beans are then simply used in the JSP page to get the information only

  • Applet that calls servlet

    How to achieve something like this: i ve got a simple applet that calls servlet or JSp. when i get the response i would like to show it like a new page canceling the previous one with applet. Please Help. I have no idea how to using the data from response produce a new page. Nay resources hints??

    In the second case:
    You want to use the URL and URLConnection to POST or GET information to the server
    that the applet came from (if not you have to sign the applet or set up policy).
    The response from the server should be opened in a new window.
    To post the data:
    http://javaalmanac.com/egs/java.net/Post.html
    This will get you a string, after you got that string you can use JSObject to call a javascript
    method.
    for example your applet:
    import netscape.javascript.*; // either in jaws.jar or plugin.jar in your lib dir
    ..... extends Applet{
    public Sting newpage;
    ... method that opens URLConnection and receives response in strRes
    this.newpage = strRes
    JSObject win;
    win = JSObject.getWindow(this);
    win.eval("methodThatOpensWindow()");
    The html page looks like
    <object ...... id="myapplet" myascript="true">
    function methodThatOpensWindow(){
    var win = window.open('','','');
    win.document.write(document.getElementById("myapplet").newpage);
    ...

  • Jsp file calling servlet two times

    hello
    i have created registration form for hospital management project in which registration form is jsp file on clicking on submit it calls servlet file which actually inserts data into database but problem is when i click on submit button it calls servlet file more than one time which leads to duplication of data.plz help in this matter, It is very important to me

    First question is are you absolutely sure that the form is being submitted twice? Did you look at the access logs to see that there are two Http requests being sent to the server?
    In tomcat you have to enable the access logs.

Maybe you are looking for