JSP conditions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chicago1985
    New Member
    • Oct 2007
    • 9

    JSP conditions

    I have a Servlet that checks for information and if there is an issue it forwards the message to presentation page (JSP). Now I want to stop using conditions in scriptlets in the JSP. Please advise how I can do it in this situation in my Tomcat 4.1.27 container. I dont have JSTL or EL due to restrictions in my environment.

    Servlet that forwards to JSP:

    [code=java]
    String gotopage = "";
    if(mydata == 1)
    {
    gotopage = /"pager.jsp?myme ssage=err";
    }
    else if(mydata == 34
    {
    gotopage = /"pager.jsp?myme ssage=duper";
    }
    else
    {
    gotopage = /"pager.jsp?myme ssage=proc";
    }


    RequestDispatch er dispatcher =
    getServletConte xt().getRequest Dispatcher(goto page);
    dispatcher.forw ard(request, response);
    ...[/code]
    JSP

    [code=java]<%
    String mymessage = request.getPara meter("mymessag e")

    if(mymessage.eq uals("err"))
    {
    out.println("Er ror on the page");
    }
    else if(mymessage.eq uals("dup"))
    {
    out.println("Du plicate issue.");
    }
    else if(mymessage.eq uals("proc"))
    {
    out.println("Pr ocess message issue");
    }
    %>[/code]

    Please advise.
  • snowfall
    New Member
    • Aug 2007
    • 56

    #2
    Originally posted by chicago1985
    I have a Servlet that checks for information and if there is an issue it forwards the message to presentation page (JSP). Now I want to stop using conditions in scriptlets in the JSP. Please advise how I can do it in this situation in my Tomcat 4.1.27 container. I dont have JSTL or EL due to restrictions in my environment.

    Servlet that forwards to JSP:

    [code=java]
    String gotopage = "";
    if(mydata == 1)
    {
    gotopage = /"pager.jsp?myme ssage=err";
    }
    else if(mydata == 34
    {
    gotopage = /"pager.jsp?myme ssage=duper";
    }
    else
    {
    gotopage = /"pager.jsp?myme ssage=proc";
    }


    RequestDispatch er dispatcher =
    getServletConte xt().getRequest Dispatcher(goto page);
    dispatcher.forw ard(request, response);
    ...[/code]
    JSP

    [code=java]<%
    String mymessage = request.getPara meter("mymessag e")

    if(mymessage.eq uals("err"))
    {
    out.println("Er ror on the page");
    }
    else if(mymessage.eq uals("dup"))
    {
    out.println("Du plicate issue.");
    }
    else if(mymessage.eq uals("proc"))
    {
    out.println("Pr ocess message issue");
    }
    %>[/code]

    Please advise.
    You can straight away assign the message to be displayed to mymessage, instead of giving err or proc.
    In the jsp u can display the msg by <%=mymessage% >

    Comment

    Working...