else block is not processed

Discussion in 'Java' started by shanutallfat@gmail.com, Jul 25, 2008.

  1. Guest

    Hi every one!
    Im new wth jsp.. i ll b grateful if ny1 can help me with this!! thankz
    in advance!

    The else condition is not getting processed in the jsp file but if
    condition processes fine!!!
    first here is the code of the html file:-
    <html>

    <body bgcolor="#ffffff">

    <form name="mod" method="post" action="emp_verify.jsp">
    <h1 align="center">Modify Employee</h1>
    <h2 align="left">Enter The Employee Id to modify the details:
    <input type="text" name="T1"> </h2>
    </form>
    <p align="left"><input type="submit" value="Submit" name="sub1"> </p>
    <hr>
    <p align="left"> &nbsp;</p>

    </body>
    </html>

    NOW THIS IS THE CODING OF emp_verify.jsp:-

    <%@page language="java" import="java.sql.*" %>

    <html>
    <body>

    <%
    String id=request.getParameter("T1");


    try{

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:eek:dbc:es123","","");


    PreparedStatement ps=con.prepareStatement("select * from addition
    where emp_id=?");
    ps.setString(1,id);

    ResultSet rs=ps.executeQuery();

    if (rs.next()) {
    %>
    <!-- when successful page turns to emp_about.jsp--!>

    <jsp:forward page="emp_about.jsp" />

    <% } else { %>

    <!--but when unsuccessfull this is not displayed --!>

    not found

    <% } %>
    <% }
    catch(Exception e){} %>

    </body>
    </html>

    when entry is found, control is properly transfered to emp_about.jsp,
    but
    when entry is not found in the database the code in else condition
    doesnt shows up!!!

    my browser- IE 7
    server- TOMCAT6.0

    plz help me with this i m new in jsp!!!
    thank you!!!
     
    , Jul 25, 2008
    #1
    1. Advertising

  2. GArlington Guest

    On Jul 25, 2:57 pm, wrote:
    > Hi every one!
    > Im new wth jsp.. i ll b grateful if ny1 can help me with this!! thankz
    > in advance!
    >
    > The else condition is not getting processed in the jsp file but if
    > condition processes fine!!!
    > first here is the code of the html file:-
    > <html>
    >
    > <body bgcolor="#ffffff">
    >
    > <form name="mod" method="post" action="emp_verify.jsp">
    > <h1 align="center">Modify Employee</h1>
    > <h2 align="left">Enter The Employee Id to modify the details:
    > <input type="text" name="T1"> </h2>
    > </form>
    > <p align="left"><input type="submit" value="Submit" name="sub1"> </p>
    > <hr>
    > <p align="left"> &nbsp;</p>
    >
    > </body>
    > </html>
    >
    > NOW THIS IS THE CODING OF emp_verify.jsp:-
    >
    > <%@page language="java" import="java.sql.*" %>
    >
    > <html>
    > <body>
    >
    > <%
    > String id=request.getParameter("T1");
    >
    > try{
    >
    > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    > Connection con=DriverManager.getConnection("jdbc:eek:dbc:es123","","");
    >
    > PreparedStatement ps=con.prepareStatement("select * from addition
    > where emp_id=?");
    > ps.setString(1,id);
    >
    > ResultSet rs=ps.executeQuery();
    >
    > if (rs.next()) {
    > %>
    > <!-- when successful page turns to emp_about.jsp--!>
    >
    > <jsp:forward page="emp_about.jsp" />
    >
    > <% } else { %>
    >
    > <!--but when unsuccessfull this is not displayed --!>
    >
    > not found
    >
    > <% } %>
    > <% }
    > catch(Exception e){} %>
    >
    > </body>
    > </html>
    >
    > when entry is found, control is properly transfered to emp_about.jsp,
    > but
    > when entry is not found in the database the code in else condition
    > doesnt shows up!!!
    >
    > my browser- IE 7
    > server- TOMCAT6.0
    >
    > plz help me with this i m new in jsp!!!
    > thank you!!!


    So, what does it do when you expect it to get to "else" part? Goes to
    "emp_about.jsp"? Or displays empty page? Or something else?
     
    GArlington, Jul 25, 2008
    #2
    1. Advertising

  3. Guest

    i want the browser window to show this- " employee id you have entered
    is not present in the database!"
     
    , Jul 25, 2008
    #3
  4. Guest

    also i ll add this-
    Employee id you have entered does not exist in the database!
    you may <a href="home.jsp">click to go home</a>
     
    , Jul 25, 2008
    #4
  5. GArlington Guest

    On Jul 25, 3:20 pm, wrote:
    > also i ll add this-
    > Employee id you have entered does not exist in the database!
    > you may <a href="home.jsp">click to go home</a>


    So, why don't you?
    What DOES it do when it does NOT find a record now?
     
    GArlington, Jul 25, 2008
    #5
  6. Guest

    Whenever i enter an ID which is not present in the database and hit
    enter, nothing happens.. the browser displays the same html file
    only!
    ( here i expect it to display " not found")
     
    , Jul 25, 2008
    #6
  7. Donkey Hot Guest

    wrote in news:42fc9cf7-ca5b-4ef7-afd9-eb8b05ac2db0
    @w1g2000prk.googlegroups.com:

    > Hi every one!
    > Im new wth jsp.. i ll b grateful if ny1 can help me with this!! thankz
    > in advance!
    >
    > The else condition is not getting processed in the jsp file but if
    > condition processes fine!!!
    >
    ><!-- when successful page turns to emp_about.jsp--!>
    >
    > <jsp:forward page="emp_about.jsp" />
    >
    ><% } else { %>
    >
    ><!--but when unsuccessfull this is not displayed --!>
    >
    > not found
    >


    You use "--!>" to close a html comment. Is't it supposed to be "-->" ?

    Dunno.. The jsp:forward should not work either, if I'm right.
     
    Donkey Hot, Jul 25, 2008
    #7
  8. Guest

    plz dont mind the wrong comments in the code, in real i have not
    inserted any comments but i used them here just to make fellow members
    understand where is my problem , here i know their syntax is wrong.
     
    , Jul 25, 2008
    #8
  9. Lew Guest

    wrote:
    > plz dont mind the wrong comments in the code, in real i [sic] have not


    Ewww! Txtsp33k!

    > inserted any comments but i [sic] used them here just to make fellow members
    > understand where is my problem , here i [sic] know their syntax is wrong.


    That makes it rather difficult for people who might try to reproduce
    your problem, only to find that your code sample fails to demonstrate
    it, or demonstrates some different problem that impedes their
    analysis.

    <http://pscode.org/sscce.html>

    --
    Lew
     
    Lew, Jul 25, 2008
    #9
  10. GArlington Guest

    On 25 Jul, 16:48, wrote:
    > plz dont mind the wrong comments in the code, in real i have not
    > inserted any comments but i used them here just to make fellow members
    > understand where is my problem , here i know their syntax is wrong.


    1. DO NOT use sms type abbreviations in newsgroups.
    2. ALWAYS copy and paste your code [and REMOVE, NOT EDIT any
    irrelevant parts].
    3. DO NOT add anything or change anything in the code.
    Then we have better chance to help you...
     
    GArlington, Jul 27, 2008
    #10
  11. GArlington Guest

    On 25 Jul, 16:40, wrote:
    > Whenever i enter an ID which is not present in the database and hit
    > enter, nothing happens.. the browser displays the  same html file
    > only!
    > ( here i expect it to display " not found")


    Do you mean it DOES NOT get submitted? It gets redirected back to
    ENTRY/search page? Or it gets redirected to details page with no info?
     
    GArlington, Jul 27, 2008
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    25
    Views:
    707
    MonkeeSage
    Oct 1, 2006
  2. morrell
    Replies:
    1
    Views:
    1,006
    roy axenov
    Oct 10, 2006
  3. kj
    Replies:
    15
    Views:
    614
    Lawrence D'Oliveiro
    May 23, 2009
  4. A
    Replies:
    8
    Views:
    851
    James Kanze
    Aug 28, 2010
  5. Gergely Kontra
    Replies:
    16
    Views:
    259
    Devin Mullins
    Sep 20, 2005
Loading...

Share This Page