Conditional forward in JSP

Following is my jsp page. I am trying to forward to another jsp depending on the conditions.
<%@ taglib uri="struts-logic" prefix="logic" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
     String u = (String)session.getAttribute("userID");
     String seibel = (String)session.getAttribute("seibel");
    System.out.println(u);
    System.out.println(seibel);
     if(seibel.equals("true"))
      {%>
      <jsp:forward page = "AutoLogin.jsp"/>;
      <%}     
     else
     %>
       <logic:redirect forward="logon"/> ;     
<%
%>When the if condition fails, the else part does not get executed. The error I get is as follows.
[exec] <Dec 28, 2007 11:48:13 AM IST> <Error> <HTTP> <101017> <[ServletContext(id=7535615,name=csr-gema,context-path=)] Root cause of ServletException
[exec] java.lang.NullPointerException
[exec] at jsp_servlet.__forwardtogema._jspService(__forwardtogema.java:107)
[exec] at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
[exec] at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1094)
[exec] at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:437)
[exec] at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:481)
[exec] at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:319)
[exec] at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:5626)
[exec] at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:685)
[exec] at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3213)
[exec] at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2555)
[exec] at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:251)
[exec] at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:219)
[exec] >
Any inputs? Please reply.

As mentioned, seibel must be null. Change your code so it's like this
     if(seibel == null || seibel.equals("true"))
      {%>
      <jsp:forward page = "AutoLogin.jsp"/>;
      <%}     
     else
     %>
       <logic:redirect forward="logon"/> ;     
<%
}However depending on what you are trying to do this may just hide your problem by
short circuiting when seibel is null. If seibel should not be null then your problem is elsewhere.

Similar Messages

  • Conditional Forwarding

    Hi,
    I read through another thread and came upon a solution for conditional forwarding. The thing is, it works great... if there is no other JSP code that may break if the condition wasn't met. The point is that because the FacesContext#responseComplete() method was called, the rest of the JSP shouldn't even try to evaluate. I pasted my example here:
    [http://pastebin.com/m3ab93f71|http://pastebin.com/m3ab93f71]
    In my example I pass a parameter to the JSP page. If the parameter wasn't present, the user should be redirected. If it was, continue processing as normal.
    Can anyone tell me why it still tries to evaluate the remainder of the JSP file when I don't pass a parameter?
    Edited by: jabalsad on May 22, 2009 5:14 AM

    file: net.eyelazors.java.TheBean
    package net.eyelazors.java;
    import javax.faces.context.FacesContext;
    import javax.faces.event.PhaseEvent;
    import java.util.Map;
    public class TheBean {
        private Map<String, String> parameters;
        private Integer id;
        public TheBean() {
        public void canLoadView(PhaseEvent event) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            parameters = facesContext.getExternalContext().getRequestParameterMap();
            String idString = parameters.get("id");
            if (idString == null) {
                facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, "no-id");
                facesContext.responseComplete();
            } else {
                Integer id = Integer.parseInt(idString);
                this.id = id;
        public String getTest() {
            return id.toString();
            public Integer getId() {
                    return id;
    }file: the_example.jsp
    <?xml version="1.0" ?>
    <jsp:root version="2.0"
                    xmlns:jsp="http://java.sun.com/JSP/Page"
                    xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:h="http://java.sun.com/jsf/html">
            <jsp:directive.page contentType="text/html"/>
            <jsp:output omit-xml-declaration="no"
                            doctype-root-element="html"
                            doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
                            doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
            <f:view beforePhase="#{TheBean.canLoadView}">
                <html xmlns="http://www.w3.org/1999/xhtml">
                            <head>
                                    <title>Example Page</title>
                            </head>
                            <body>
                                    <h:outputText value="Since the ID has successfully loaded (we hope), this should display without any warnings ;)"/><br />
                                    <h:outputText value="ID = #{TheBean.test}"/>
                            </body>
                    </html>
            </f:view>
    </jsp:root>file: faces-config.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
        version="1.2">   
        <managed-bean>
            <managed-bean-name>TheBean</managed-bean-name>
            <managed-bean-class>net.eyelazors.java.TheBean</managed-bean-class>
            <managed-bean-scope>request</managed-bean-scope>
        </managed-bean>
        <navigation-rule>
            <from-view-id>/the_example.jsp</from-view-id>
            <navigation-case>
                    <from-outcome>no-id</from-outcome>
                    <to-view-id>/index.jsp</to-view-id>
                    <redirect />
            </navigation-case>
            </navigation-rule>
        <navigation-rule>
            <from-view-id>/index.jsp</from-view-id>
            <navigation-case>
                    <from-outcome>with-id</from-outcome>
                    <to-view-id>/the_example.jsp</to-view-id>
            </navigation-case>
            <navigation-case>
                    <from-outcome>without-id</from-outcome>
                    <to-view-id>/the_example.jsp</to-view-id>
            </navigation-case>
            </navigation-rule>
    </faces-config>
    file: index.jsp
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <f:view>
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>Front Page</title>
            </head>
            <body>
                    <h:form>
                            <h:outputText value="Welcome to the front page."/><br />
                                    <h:commandLink value="With ID (100)" action="with-id">
                                            <f:param name="id" value="100"/>
                                    </h:commandLink><br />
                                    <h:commandLink value="Without ID" action="without-id"/>
                            </h:form> 
            </body>
        </html>
    </f:view>

  • How to forward a JSP page to another dynamically generated JSP

    Hi gurus,
    I have a problem with forwarding a JSP page, to another dynamic jsp page.
    I have to forward a jsp page to (say X1 ) to another JSP page (say X2).
    Iam choosing the name of the page X2, dynamically from a list of JSP pages in a directory depending upon some parameters.
    Here is my code for ur better understanding...
    <java>
    // this gives me the name of the page X2 to which my page X1 should be forwarded.
    <TR> <TD><%=request.getParameter("codeins")%></TD></TR>
    <%
    if(request.getParameter("codeins").length() != 0)
    %>
    // if i use this forward tag i get the error
    <a href=" 
                <jsp:forward page=Ins/<%=request.getParameter("codeins")%">.jsp">
         <jsp:param name="a" value="<%=request.getParameter("a")%>" />     
         <jsp:param name="b" value="<%=request.getParameter("b")%>" />
         <jsp:param name="c" value="<%=request.getParameter("c")%>" />
         <jsp:param name="p" value="<%=request.getParameter("p")%>" />
         <jsp:param name="q" value="<%=request.getParameter("q")%>" />
    </jsp:forward>">GNSS Instantiation</a>
    <%
    else {
    out.println("No entry in the database! ");
    } %>
    </java>
    I am getting the exceptions like
    <java>
    org.apache.jasper.JasperException: /Newspg.jsp(162,67) equal symbol expected
         at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
         at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:428)
         at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:126)
         at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:169)
         at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:136)
         at org.apache.jasper.compiler.Parser.parseForward(Parser.java:517)
         at org.apache.jasper.compiler.Parser.parseAction(Parser.java:661)
         at org.apache.jasper.compiler.Parser.parseElements(Parser.java:803)
         at org.apache.jasper.compiler.Parser.parse(Parser.java:122)
         at org.apache.jasper.compiler.ParserController.parse(ParserController.java:199)
         at org.apache.jasper.compiler.ParserController.parse(ParserController.java:153)
         at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:227)
         at org.apache.jasper.compiler.Compiler.compile(Compiler.java:369)
         at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
         at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
         at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
         at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:430)
         at org.apache.jsp.SPVariablesg_jsp._jspService(SPVariablesg_jsp.java:425)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
         at java.lang.Thread.run(Thread.java:534)
    </java>
    please help me out to let me know, where iam doing wrong.
    Thanx
    mark.

    Hi,
    in reference to the above subject i did like to know what is wrong in the following code of mine:
    <%
         String name = "admin"; // this is line which is being indicated in error message
         int password = 4589;
    %>
    <!-- <script language="javascript" src="init.js"></script> -->
    <head>
    <script>
    function checking()
         if name != document.test.user.value || password != document.test.password.value)
              alert("ur not authorised to view the requested url");
              forward("Firstpage.jsp");
    %>
    </script>
    its says :
    org.apache.jasper.JasperException: /webpg/Dec2Firstpage.jsp(4,21) equal symbol expected
    any solutions?
    thanx in advance

  • Timed redirection/forward in jsp

    i am trying to forward the request/response to another page after a particular peroid of time say 10 seconds. I need to output the content and wait for 10 seconds till forward happens. I think you got , what i need to do ...
    i know a forward cant happen after buffer is flushed ..
    plz suggest a way
    SHERIN :)
    THIS IS PART OF JSP CODE
    if(reportStat.equals("first"))
    %>
    <FORM action="/IntranetSystem/report" method="post">
         <CENTER>
              <b><FONT color="red">ENTER YOUR DAILY REPORT</FONT></b><br><br><br>
         <TEXTAREA rows="10" name="report" cols="50" ></TEXTAREA>
         <br><br>
         <INPUT type="submit" value=" submit "/>
         <INPUT type="hidden" name="userid" value="<%=userId%>" />
    </FORM>
    <%     }else if (reportStat.equals("success")){   %>
              <CENTER>
              <h3> DAILY REPORT UPDATED </h3><br><br>
              <b><FONT color="red">Redirecting to Home page in 10 seconds...</FONT></b>
              </CENTER>
              <%
                   out.flush();
                   out.append('x');
                   Thread.sleep(10000);
                   out.println("redirecting..");
              %>
              <jsp:forward page="inbox.jsp"> // THIS CAUSES ILLEGALSTATEEXCEPTION
              <jsp:param value="<%=userId%>" name="userid"/>
              </jsp:forward>
    <%     }else{    %>
              <CENTER>
              <FONT color="red">
              <h3> DAILY REPORT UPDATE FAILED </FONT><br>check todays attendance status . you may not have signed in</h3><br><br>
              <FONT color="yellow"><b>Redirecting to Home page in 10 seconds... </b></FONT>
              </CENTER>
              <%
                   out.flush();
                   out.append('x');
                   Thread.sleep(10000);
                   out.println("redirecting..");
              %>
              <jsp:forward page="inbox.jsp">
              <jsp:param value="<%=userId%>" name="userid"/>
              </jsp:forward>
    <% } %>

    But what is the requirement. I dont think really u r going to do some thing in 10seconds.
    u just want to do that,coz u want to show some thing fancy ,to the user. ..lol :)
    That will slightly affect the performence,no doubt on that.

  • Forward to JSP page without using Navigation Model

    How can I forward to a JSP page without using the Navigation Model?

    It's done in the cardemo example in
    ImageMapEventHandler.processAction() Is there a reason
    for it there?Ah ... that makes sense.
    That code in CarDemo was written before there was such a thing as a NavigationHandler, and we didn't have time to update it to the new approach before the EA4 release. That'll be changed before the next one. In the mean time, I'd recommend that you use the navigation rules mechanism where it works for you, because it encourages good separation of business logic and presentation logic that will lead to more maintainable applications.
    Craig

  • Forward to JSP in default-webapp

    I have a servlet in a deployed .war file on Sun Java System Web Server 6.1. I have a JSP that is not deployed in any .war file. How do I forward from the servlet to the JSP. I can't figure out how to obtain a context to the jsp pages in the default webapp which are outside of a .war file.
    I see that the jsp .class files are in /opt/sun/web/https-c3qweb1/ClassCache/https-c3qweb1/default-webapp where https-c3qweb1 is the name of our virtual server. There is not an explicit WEBAPP entry for the default webapp in server.xml.
    Is it possible to obtain the context of these jsps which are outside of .war files?

    I got this to work by doing the following:
            ServletConfig currentConfig = getServletConfig();
            ServletContext otherContext = currentConfig.getServletContext().getContext("/");
            RequestDispatcher dispatch = otherContext.getRequestDispatcher("/mbttest.jsp");
            request.setAttribute("anattribute", "set by DispatchOtherContext redirector servlet");
            dispatch.forward(request, response);

  • Mapping webapp URLs to a single servlet which forwards to JSP

    I am using JSP for page presentation, but I want to have all requests
              intercepted by a servlet, which will perform various functions before
              forwarding to the requested JSP page. In general, I want the URL to
              reflect the target JSP page, to facilitate bookmarking. I'm using a
              web application to deploy the servlet+JSPs.
              Ideally, I wanted to have all request URLs look like a request for the
              JSP page without the .jsp extension (so
              http://hostname/webapp/here/there maps to /here/there.jsp within
              webapp). However, I can find no provision in web.xml for mapping all
              URLs without extensions to a specific servlet. I can use '/' to map
              all requests to the servlet, but then even image or HTML requests
              get intercepted (and trashed).
              On the other hand, if I map '*.jsp' to the servlet, then when I try to
              forward to the actual JSP page, the servlet gets invoked again
              recursively.
              I could create an arbitrary extension and map it to the servlet, and
              then have the servlet replace my custom extension with '.jsp' before
              forwarding, but this seems a bit funky.
              Has anyone come up with a better solution to this, within the context
              of a webapp? Seems like it should be a not-uncommon scenario.
              Thanks,
                                  -- Peter
              

    Yes, you can! It depends on how you access the servlet. If you access it via GET method you must add a request parameter to the url to distinguish from which jsp the request comes. If you use POST method (with form submission) put a hidden field in the form and with that field you can recognize from which jsp the request comes.
    Message was edited by:
    amittev

  • Weird behaviour with jsp:forward and jsp:param

    I'm running Orion 1.5.3
    Wanted to ask if anyone has insight into the following.
    I'm trying to do a forward with a parameter. The parameter is something like a message string.
    The following does not work.
    <%
    String result = "unsucessful"; // retrieved from external source... hardcoded for example's sake
    %>
    <jsp:forward page="<%=nextPage%>">
    <jsp:param name="message" value="The result was <%=result%>"/>
    </jsp:forward>
    I've managed to deduce that the error is in the param value. Apparently, we cannot mix variables with static values inside the value parameter.
    I've managed to get it working by doing this...
    <%
    String result = "unsucessful"; // retrieved from external source... hardcoded for example's sake
    String message = "The result was " + result;
    %>
    <jsp:forward page="<%=nextPage%>">
    <jsp:param name="message" value="<%=message%>"/>
    </jsp:forward>
    My question is, is this a bug or is it supposed to be this way ? Can we mix the value parameters ?

    Hi Bernard,
    Take a note of the following syntax -
    <jsp:forward page={"relativeURL" | "<%= expression %>"} >
    <jsp:param name="parameterName"
    value="{parameterValue | <%= expression %>}" />+
    </jsp:forward>
    It is evident that either the value attribute can have an expression or simple text.
    I have tried your example and I am also encountering the same kind of problem, but I have found a way out.
    You can try the following in your code -
    <%
    String result = "unsucessful"; // retrieved from external source... hardcoded for example's sake
    %>
    <jsp:forward page="<%=nextPage%>">
    <jsp:param name="message" value=' <%= "The result was" + result%>'/>
    </jsp:forward>
    Instead of using
    value= "The result was <%=result%>" you can use
    value= '<%= "The result was" + result%>'.
    Hope this helps

  • PageContext.forward("NewPage.jsp") appends previous page's data

    Hi!
              When I try to use the above mentioned forward, I get to NewPage.jsp, but
              all of the data from OldPage.jsp is appended to the bottom of the
              NewPage. I have tried using requestDispatcher.forward() as well with the
              same results. How should I do this?
              Weblogic 5.1 with SP 6 on Solaris.
              thanks
              Colleen
              

    OOPS and I forgot to mention that this is in a custom tag, not just on the
              jsp page.
              Colleen Wtorek wrote:
              > Hi!
              >
              > When I try to use the above mentioned forward, I get to NewPage.jsp, but
              > all of the data from OldPage.jsp is appended to the bottom of the
              > NewPage. I have tried using requestDispatcher.forward() as well with the
              > same results. How should I do this?
              >
              > Weblogic 5.1 with SP 6 on Solaris.
              >
              > thanks
              > Colleen
              

  • How to forward a jsp page in flex application ( when a button is clicked)

    i am a fresher to this FLEX 2.0 , i designed the UI part in
    flex, but when i click the submit button it has to forward to the
    JSP page to check against the valid user,password , so how to
    forward the page to jsp(i mean from flex to jsp) , if u can suggest
    me with an example, it will be easy for me, is Flex Data Service 2
    is necessary for this
    thanks for ur speedy reply, hopping to get the solution for
    this issue,
    sandeep

    Your JSP is, as far as Flex is concerned, just a data service
    which it will request and read its response. I'd suggest using
    <mx:HTTPService>. For example:
    <mx:HTTPService id="authorize" url="validate.jsp"
    fault="handleFault(event)" result="handleResult(event)">
    <mx:request>
    <userid>{username.text}</userid>
    <password>{password.text}</password>
    </mx:request>
    </mx:HTTPService>
    Flex creates the request:
    http://{server}.{port}{context.root}/validate.jsp?userid=fred&password=flintstone
    assuming that you have <mx:TextInput id="username" />
    and <mx:TextInput id="password" /> components.
    Your Submit button then does: authorize.send()
    (note: you can also pass the request parameters in the send()
    method - check the Flex docs on HTTPService).
    Flex will listen for the response from your JSP. Typically a
    JSP would respond with an HTML page, but you don't want to do that
    for Flex. Your JSP should produce either a simple string ("yes" or
    "no" or "error" etc) or an XML document.
    The handleResult method can examine the response and do
    what's necessary.

  • Conditional placement of jsp tags ?

    based on some test, i want to determine whether or not to place the </tag> closing element for a tag. im using this tag library now which works great
    http://www.guydavis.ca/projects/oss/tags/
    the problem is the same i encountered with other similar tag libraries. i need to conditionally place tags in my jsp file based on certain tests. not only that, but i need to conditionally include the closing element ( </tag> for example)
    is this possible, since the tags are translated at the same time as the jsp ?
    anyone got an example or an alternative ?
    help ?

    I'd use JSTL to make it happen. It's got the <c:if> and <c:choose> tags that are great to work with. AND they keep that ugly, unreadable, unmaintainable scriptlet code out of your JSPs. JMO - MOD

  • Way to forward in JSP  to a different URL

    Hi,
    I need to forward the user to a different page keeping the sensitive user information(like credit card details). The problem is that the forward function seems to be looking for the URL inside the same home.
    If I'm trying to forward from http://www...../app1 to http://www...../app2 the forward function looks for the app2 inside app1 folder and I'm getting the error page not found.
    Thanks.

    Generally,<jsp:forward> element forwards the request object containing the client request information from one JSP file to another file, in the same application context as the forwarding JSP file.
    <jsp:forward page={"relativeURL" | "<%= expression %>"} />
    The relative URL looks like a path-it cannot contain a protocol name, port number, or domain name. The URL can be absolute or relative to the current JSP file. If it is absolute (beginning with a /), the path is resolved by your Web or application server.
    Also, To forward the request to another context, try out the following method :
    To forward from Context ct1 to Context ct2:
    1) Turn the crossContext attribute to "true" in server.xml
    2) In your code:
    <% ServletContext ctxB = application.getContext("/ct2");
    RequestDispatcher rdB = ctxB.getRequestDispatcher ("<file_name_relative_to_context_ct2");
    rdB.forward(request, response); %>

  • Nullpointer when forwarding to JSP

    Hello...
    I'm recieving a Nullpointer exeption in the line marked with 1):
    private void gotoPage(String address, HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    1) RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(address);
    dispatcher.forward(request, response);
    I'm trying to forward to address /JSP/LoginSuccess.jsp but a plain HTML file also gives an Nullpointer.
    Stranges thing is. I'm receiving this exception since i changed the init of my servlet from having no arguments to having init (ServletConfig config).
    Any ideas?
    Thanks very much.

    Stranges thing is. I'm receiving this exception since
    i changed the init of my servlet from having no
    arguments to having init (ServletConfig config).
    The init(config) is called bythe servlet container and the servlet stores the config and ServletContext objects but by overriding this method you have hidden the code where the ServletContext object gets stored so your call to getServletContext now returns null. Make sure you call the super.init(config) method.
    From the servlet api:
    public void init(ServletConfig config)
    throws ServletExceptionCalled by the servlet container to indicate to a servlet that the servlet is being placed into service. See Servlet.init(javax.servlet.ServletConfig).
    This implementation stores the ServletConfig object it receives from the servlet container for later use. When overriding this form of the method, call super.init(config).

  • How to conditionally forward a request to a Servlet for processing?

    Hi,
    I am writing a middleware application, where the application receives HTTPRequest from front end, and based on the URL string it will forward the request to one of the servlets which will handle the processing.
    I need ideas about what is the best way to write the forwarding logic. Should it be a Servlet Filter, or an initial Servlet that only does forwarding? Any code samples will be greatly appreciated.
    Thanks.

    This is almost textbook definition of a Controller Servlet. I would use a Servlet that switches on what option needs to be performed and forwards to the proper URL.

  • Forwarding to jsp page inside web-inf

    hi everyone,
    i have a question. i have jsp pages inside web-inf folder and i have welcome page of project(outside web-inf) in pages from where i want to give link to jsp page inside web-inf folder. this project is absed on spring framework. how can i do this?
    thanks in advance

    hi everyone,
    i have a question. i have jsp pages inside web-inf folder and i have welcome page of project(outside web-inf) in pages from where i want to give link to jsp page inside web-inf folder. this project is absed on spring framework. how can i do this?
    thanks in advance

Maybe you are looking for

  • Cannot install BB desktop software 4.7

    every time i try to install 4.7 on my computer, the programme stopped after i select the country. it gives me information as below: the wizard was interrupted before Blackberry Desktop Software 4.7 could be completely installed i can install 4.7 on m

  • Sample ALV Report

    Hi, Please help me with some sample ALV reports for SAP HR. Rgds Preeti Saun

  • Template for transport

    i want to know whether a Template can be created in which we can pre define all the files or objects that should be selected for a transport.

  • AirPlay icon is missing how do I restore on ipad3

    Need help missing AirPlay icon to toggle my ipad3 to my apply tv. Tried restore no luck new iPad and apple tv looks simple but icon does not exist am I missing something is there an app I have to download. Thanks

  • Airport Express Gone With the Wind!

    I recently bought a new PB G4 17-inch laptop (non-Intel version) to update/replace my 15-inch PB G4 Titanium laptop (which I plan to give to my oldest son). I transferred all the files from my old PB through the firewire cable option. It did a great