JSP to Servlet to JSP

Hi,
Is it possible to have a JSP that does an include() of a servlet which in turn includes another JSP? I'm trying to get this to work and cannot... :-(
Thanks

i think its possible.
<c:import url="/MyServlet"/>
I think u know this piece its mapping will be in web.xml which would forward/ delegate the control to that Servlet and in the service method u could set a param on request so that when the control comes back to the jsp page u have the param and depending on that param u can include any other jsp fragment.
sien

Similar Messages

  • Session Rules from Servlet to JSP

    I'm getting a null pointer exception from the else statement in the JSP below when I check to see if a user has been authenticated by a servlet.
    Are there any problems with the else statement to cause an exception?
    <% /**Verify Authenticationt*/
    HttpSession mysession = request.getSession();
    String loginUrl = "/hr/servlet/SessionLoginServlet";
    if (mysession==null)
    response.sendRedirect(loginUrl);
    else {  //below code causing null pointer exception
    String loggedIn = (String) mysession.getAttribute("loggedIn");
    if (!loggedIn.equals("true"))
    response.sendRedirect(loginUrl);
    %>
    The Servlet's doPost:
    public void doPost(HttpServletRequest request, HttpServletResponse
    response)throws ServletException, IOException {
    String userName = request.getParameter("userName");
    String password = request.getParameter("password");
    if (login(userName, password, response)) {
    //send cookie to the browser
    HttpSession session = request.getSession(true);
    session.setAttribute("loggedIn", new String("true"));
    response.sendRedirect("/hr/jsp/PAStart.jsp");
    else {
    sendLoginForm(response, true);
    }

    Unfortunately, no. You'll need to say:
    if (loggedIn != null || !loggedIn.equals("true"))
    It's how the equals() works for String objects. You need two objects to check equality.

  • Passing values from a jsp to a servlet

    I have a jsp which has a search form for customers, first it lets you search by colour, giving options of red, white or all, then gives three options of what price. Im trying to get my servlet to read these choices, and display the results. I have a statement in my serlvet which says:
    String price = request.getParameter("search preference colour");
    and the statment in the JSP is:
    <select name="search preference colour">
    <option value="Red">red</option>
    <option value="White">White</option>
    <option value="All">All</option>
    </select>
    I need to know how to define which option has been chosen, and have the chosen results displayed. I tried an 'if' statement but it didnt seem to work. Thanks

    yuvi wrote:
    i have a servlet from which i am passing result set values to a jsp page.Basically they are database records from a table named basic.
    and these selective fields have to be dissplayed on jsp.i have tried incorporating values into session variables and using them on jsp.it works fine for single record but when there are multiple results it fails!! :(Learn JSTL and use tags. Scriptlet code in JSPs is a bad idea.
    %

  • How to get multiple selections from jsp page in my servlet

    Hello Everyone,
    I've a list that allows users to make multiple selections.
    <select name=location multiple="multiple">
        <option>
             All
        </option>
        <option>
             Hyd
        </option>
        <option>
             Dub
        </option>
        <option>
             Mtv
        </option>
      </select>I want to get the selections made by user in jsp page from my servlet, selections can be multiple too.
    ArrayList locList = new ArrayList();
    locList = request.getParameter("location");when I do so, I get compilation error as the request returns string type. How do I then get multiple selections made by the user.
    Please let me know.

    For those kind of basic questions it would help a lot if you just gently consult the javadocs and tutorials.
    HttpServletRequest API: [http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html]
    Java EE tutorial part II: [http://java.sun.com/javaee/5/docs/tutorial/doc/]
    Coreservlet tutorials: [http://courses.coreservlets.com/Course-Materials/]

  • How to get the query values from the url in a servlet and pass them to jsp

    ok..this is the situation...
    all applications are routed through a login page...
    so if we have a url like www.abc.com/appA/login?param1=A&param2=B , the query string must be passed onto a servlet(which is invoked before the login page is displayed)..the servlet must process the query string and then should pass all those values(as hidden values) to the login jsp..then user enters username and pswd, then there should be another servlet which takes all the hidden values of jsp and also username and pswd, authenticates the user and sends the control back to that particular application along with the hidden values...
    so i need help on how to parse the query string from the original url in the servlet, pass it out to jsp, and then pass it back to the servlet and back to the original application...damnn...any help would be greatly appreciated...thanks

    ok..this is the situation...Sounds like you have a bad design on your hands.
    You're going to send passwords in a GET request as clear text? Nice security there.
    Why not start with basic security and work your way up?
    %

  • Retrieve values from a table of a JSP page in Servlet.

    Hello all,
    I am new in JSP servlet world, I want to create a grid on JSP page using Servlet.
    Suppose i have some records in a JSP page and This JSP page will display these records in a tabular form. And, on a button click that table data should be
    accessible in servlet,
    Now, How can i traverse among all the rows of that table of JSP page in servlet. or How can i retrieve a specific cell record of that table of JSP page in servlet.
    Can anyone please answer this.
    Thank you and regards.

    Hi,
    Create in your HTML form inputs with the same name i.e.:
    <input name="a[]" value="2" >
    <input name="a[]" value="9" >
    In your jsp page use :
    String Values[] = request.getParameterValues("a[]") ;
    This will give you a string array of two elements.
    for (int x = 0; x < Values.length; x++)
        System.out.println(Values[x]) ;
    }Will print :
    2
    9
    Hope this helps.
    Bill Moo

  • Request parameter from jsp in servlet

    i need to know what is the complete code in servlet
    to get parameters from the fragment code shown below in a jsp file.
    Neddng it urgent, thank in advance, take care.
    <form method="get">
    field: <input type="text" name="field">
    <br>
    tablename: <input type="text" name = "tablename"><br>
    <jsp:forward page="hello.jsp">
    <jsp:param name ="field" value="field"/>
    <jsp:param name = "tablename" value="tablename"/>
    </jsp:forward>
    <br><br>
    <input type="submit" value="Submit">
    </form>

    If I understand anything...
    TO let it have some sense:
    <form method="get">
    field: <input type="text" name="field">
    <br>
    tablename: <input type="text" name = "tablename"><br>
    <% if(request.getParameter("field")!=null) { %>
    <jsp:forward page="hello.jsp">
    <jsp:param name ="field" value="field"/>
    <jsp:param name = "tablename" value="tablename"/>
    </jsp:forward>
    <%}%>
    <br><br>
    <input type="submit" value="Submit">
    </form>
    import java.io.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    * @author  akulinsk
    * @version
    public class NewServlet extends HttpServlet {
        /** Initializes the servlet.
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        /** Destroys the servlet.
        public void destroy() {
        /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            String field = request.getParameter("field");
            String tablename = request.getParameter("tablename");
            //DO SOMETHING HERE
            out.close();
        /** Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Returns a short description of the servlet.
        public String getServletInfo() {
            return "Short description";
    }

  • Urgent....How can i redirect to my jsp page from servlet in init() method..

    How can i redirect to my jsp page from servlet in init() method..Becoz that servlet is calling while server startsup..so im writing some piece of code in init() method..after that i want to redirect to some jsp page ...is it possible?
    using RequestDispatcher..its not possible..becoz
    RequestDispatcher rd = sc.getRequestDispatcher("goto.jsp");
    rd.foward(req,res);
    Here the request and response are null objects..
    So mi question can frame as how can i get request/response in servlet's init method()..

    Hi guys
    did any one get a solution for this issue. calling a jsp in the startup of the servlet, i mean in the startup servlet. I do have a same req like i need to call a JSP which does some data reterival and calculations and i am putting the results in the cache. so in the jsp there in no output of HTML. when i use the URLConnection i am getting a error as below.
    java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:707)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:705)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:519)
    at com.toysrus.fns.alphablox.Startup.callJSP(Unknown Source)
    at com.toysrus.fns.alphablox.Startup.init(Unknown Source)
    at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
    so plz do let me know how to call a jsp in the start up of a servlet.
    Thanks
    Vidya

  • How to get the data of table from JSP to Servlet?

    Hi,
    I have a dynamic editable table of 3 columns on a jsp. On click on any cell the usr can edit the data. Now on click of submit button on the jsp I need to submit or get the whole data of all the rows to a servlet which would further process it.
    How do I do that?
    TIA.

    I am not sure whether u r getting my doubt or not
    properly. I am populating the table data in an
    arraylist of DO. with this arraylist I am displaying
    the data on the Screen.
    <%
    for(int i=0;i<alList.size();i++)
    DO d = alList.get(i);
    %>
    <Table>
    <tr>
    <td><%=d.getfirstField()%></td>
    <tr>
    </Table>
    <%
    %>
    The above code sniipet displays the data on screen.
    But as table being editable i would change the data
    in the cell and submit .
    So how do i capture this data? I cannot name the cell
    becos I am not sure how many rows would be displayed.
    In servlet I would use request.getParameter(?);
    TIAIf you table is editable nad has input field to edit then "malcolmmc's " answer will work perfectly.
    you can also use hidden form fields to use those vaues at servlet like this
    <input type="hidden" name="UniqueName' value="<%=d.getfirstField()%>'>
    Here UniqueName should be the unique for each cell value so that on servlet you can fetch these values using request.getParameter("UniqueName").

  • Problem with JSP and Java Servlet Web Application....

    Hi every body....
    I av developed a web based application with java (jsp and Java Servlets)....
    that was working fine on Lane and Local Host....
    But when i upload on internet with unix package my servlets and Java Beans are not working .....
    also not access database which i developed on My Sql....
    M using cpanel support on web server
    Plz gave me solution...
    Thanx looking forward Adnan

    You need to elaborate "not working" in developer's perspective instead of in user's perspective.

  • Problem with post and get (jsp to servlet)

    ===jsp code(login.jsp)
    out.println("<form action='servlet/Login' action='post'>");
    out.println("Username <input type='text' name='user' /><br>");
    out.println("Password <input type='password' name='pass' /><br>");
    out.println("<input type='submit' value='Login' /><br></form>");
    the above jsp page is included in another jsp page
    ===jsp code(index.jsp)
    <jsp:include page='login.jsp' flush='true'/>
    when submit is clicked in the login form, the data is send (to Login servlet) in the url string, even though i am using "POST" method in the form.
    the output of request.getMethod() in the Login servlet gives "GET"
    what could be the problem?

    The code you've shown us looks fine. The problem isn't in the form code you've listed. Is the form being included inside another form on index.jsp? Does index.jsp have any forms of it's own? Perhaps you aren't submitting the form you think you are submitting. Or, are you redirecting in your serlvet somewhere? Or are you forwarding the request somehow?
    I agree with the previous post - we need to see the HTML output that index.jsp results in.
    Michael

  • Problem with displaying BLOB images on JSP page using a servlet

    hi. I have a big problem with displaying BLOB images using JSP. I have a servlet that connects to the oracle database, gets a BLOB image , reads it, and then displays it using a BinaryStream. The problem is , this works only when i directly call that servlet, that is http://localhost:8080/ImageServlet. It doesn't work when i try to use that servlet to display my image on my JSP page (my JSP page displays only a broken-image icon ) I tried several coding approaches with my servlet (used both Blob and BLOB objects), and they work just fine as long as i display images explicitly using only the servlet.
    Here's what i use : ORACLE 10g XE , Eclipse 3.1.2, Tomcat 5.5.16 , JDK 1.5
    here is one of my image servlet's working versions (the essential part of it) :
                   BLOB blob=null;
              rset=st.executeQuery("SELECT * FROM IMAGES WHERE ID=1");
              while (rset.next())
                   blob=((OracleResultSet)rset).getBLOB(2);
              response.reset();
              response.setContentType("image/jpeg");
              response.addHeader("Content-Disposition","filename=42.jpeg");
                    ServletOutputStream ostr=response.getOutputStream();
                   InputStream istr=blob.getBinaryStream(1L);
                    int size=blob.getBufferSize();
              int len=-1;
                    byte[] buff = new byte[size];
                         while ((len=istr.read( buff ))!=-1 ) {
                   ostr.write(buff,0,len);
             response.flushBuffer();
             ostr.close(); and my JSP page code :
    <img src="/ImageServlet" border="0"  > If you could just tell me what i'm doing wrong here , or if you could show me your own solutions to that problem , i would be very greatful ,cos i'm realy stuck here , and i'm rather pressed for time too. Hope someone can help.

    I turns out that it wasn't that big of a problem after all. All i had to do was to take the above code and place it into another JSP page instead of into a servlet like i did before. Then i just used that page as a source for my IMG tag in my first JSP. It works perfectly well. Why this doesn't work for servlets i still don't know, but it's not a problem form me anymore . Ofcourse if someone knows the answer , go ahead and write. I would still appriceatte it.
    here's the magic tag : <img src="ImageJSP.jsp" border="0"  > enjoy : )

  • Problem with JSP and servlet in Tomcat

    hello all,
    I have made a simple hello world in Eclipse and Tomcat, it works well on my localhost, but now that I try to run it on the server in our lab I got this exception:
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Implementing class
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    java.lang.IncompatibleClassChangeError: Implementing class
         java.lang.ClassLoader.defineClass1(Native Method)
         java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1815)
         org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:869)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1322)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1201)
         org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:127)
         org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:65)
         java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
         java.lang.Class.getDeclaredConstructors0(Native Method)
         java.lang.Class.privateGetDeclaredConstructors(Class.java:2328)
         java.lang.Class.getConstructor0(Class.java:2640)
         java.lang.Class.newInstance0(Class.java:321)
         java.lang.Class.newInstance(Class.java:303)
         org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:148)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    I have transfered the web.xml file and lib and classes folder in a WEB-INF folder and also all the JSP files. I can see he JSP file, but the 'hello worl' does not work and gives this exception!
    Does any one have any idea what could be the problem?
    thanks a lot
    Mitra

    seems the web Server code previously loaded a class only when it was used rather than when it was referenced,
    ask your question in the tomcat-user mailing ! !!!

  • 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

  • PL/SQL vs JSP vs Servlets

    We are in the stage of deciding which language to develop portlets. I lean towards JSP or servlets for the wide array of Java libraries we can use. I think the only advantage of PL/SQL is speed. Thanks.

    It depends. If your developers are mainly Java developers, you'll probably prefer building web portlets. But if you have a strong PL/SQL skill set you could choose the latter. Additionally, if you're developing content that is database intensive you may want to build PL/SQL portlets since they transact with the database faster. If you're going to aggregate content from various web sites, using web providers is preferable. It's a matter of choice based on your requirements and preferences.

  • JSP form values lost upon servlet request (RequestDispatcher)

    Hello,
    I have a query screen (jsp) that calls a servlet and gets results. However, although the results or errors display just fine (I do a setAttribute for them), I lose the initial values in the query form (values that the user input - which are stored in the request object). Shouldn't those values be maintained and displayed, since I'm using the RequestDispatcher and thus, I should have the same request object? Thank you, C Turner
    *****My JSP (the related code)*****
    <jsp:useBean id="form" class="com.foo.ActivityBean" scope="session">
    <jsp:setProperty name="form" property="*"
    </jsp:useBean>
    <HTML>
    <BODY>
    <FORM ACTION="ActivityFormHandler" METHOD="POST">
    <P><B>From Date</B>
    <INPUT TYPE="TEXT" NAME="fromDate" SIZE="9" VALUE="<jsp:getProperty name="form" property="fromDate"/>">
    <P><B>To Date</B>
    <INPUT TYPE="TEXT" NAME="fromDate" SIZE="9" VALUE="<jsp:getProperty name="form" property="toDate"/>">
    *****Java from my HttpServlet, ActivityFormHandler (acting as a formhandler)*****
    if (errors.size() == 0) {
    ActivityBean myActivityBean = new ActivityBean();
    myActivityBean.setBeanQueryValues(acctNumber, department, fromDate, toDate);
    Vector resultsVector = null;
    try {
    resultsVector = myActivityBean.executeQuery();
    } catch (CreateException ce) {
    errors.add("There was a problem retrieving the requested data from the database.");
    request.setAttribute("results", resultsVector);
    } else {
    //Data is not okay.
    String[] errorArray = (String[])errors.toArray(new String[errors.size()]);
    request.setAttribute("errors", errorArray);
    RequestDispatcher rd;
    rd = getServletContext().getRequestDispatcher("/public_html/ActivityQuery.jsp");
    //rd.forward(request, response);
    rd.include(request, response);

    For those interested in my question, here's what I figured out.
    Instead of:
    <INPUT TYPE="TEXT" NAME="fromDate" SIZE="9" VALUE="<jsp:getProperty name="form" property="fromDate"/>">
    Use:
    <INPUT TYPE="TEXT" NAME="fromDate" SIZE="9" VALUE="<%out.print(request.getParameter("fromDate"));%>">
    This allows the input field to persist the query value instead of blanking it out when the results are displayed. -ct

Maybe you are looking for

  • BPM - Message interfaces of one component are not appearing in another comp

    Hi, We have created 2 software components(X and Y) for File to RFC scenario. "X" SWC is dependent on "Y" SWC. We are building sync-async bridge using BPM. We have created one BPM in X component. This BPM has the visibility of message interfaces only

  • How can i get the exact Range of  codePoints of every UnicodeScript(Block)?

    hello dear all, this problem has puzzled me for a long time. how can i get the exact Range of codePoints of every UnicodeScript(Latin,Han,.....) or UnicodeBlock(Basic_Latin, Latin-1 Supplement, Linear B,......)? so that i can do some iterations to di

  • Event in Table maintenance generator

    Hi, We are using the event in the table maintainenace to validate the data entred by the user. In one of the scenarios when user does enter anything and press enter , an error message should come. I have created a form on event 01-before saving the d

  • Multiple Trusted Recon Sources

    I recently attended an Oracle OIM training. We were told that you can not have multiple trusted recon sources. This is a feature coming in the next release of OIM. I have read a few posts where it seems you can. The simple business case is that we ha

  • Setting Content-Type in .jspx file

    Hello, My application is not rendered by an HTML Browser. I need to set the contentType to application/x-ywidget+xml in my JSPX file. The content type returned is always text/xml !!! I have tried: 1. To create a phaseListener and overloading before o