Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

URGENT setting variable equal to session variable

I have a page in which i want to show the details of a patient but i am getting a problem. Think there is a problem with setting a variable equal the value of session variable. I am gettinmg the following problem:

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.

G:\Apache\work\Standalone\localhost\_\sad\updatetry$jsp.java:124: 'catch' without 'try'.
        } catch (Throwable t) {
          ^

G:\Apache\work\Standalone\localhost\_\sad\updatetry$jsp.java:132: 'try' without 'catch' or 'finally'.
}
^

G:\Apache\work\Standalone\localhost\_\sad\updatetry$jsp.java:132: '}' expected.
}
 ^
3 errors, 1 warning

This is the code i have at moment:


 <%
                              
String user  = session.getAttribute( "Name" ) ;
session.setAttribute( "Name", user );
       // Create a result set containing all data from my_table
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM TblPatient where PatientID = '" + user + "'");

%>
<%while (rs.next ()){%>
                  Current Details for Patient:<%= session.getAttribute( "Name" ) %></span><br>
                  <br>
                </font></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td width="588" align="center"> <form name="form1" method="post" action="registered.jsp">
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                        <td width="17%"><strong>ID No:</strong></td>
                    <td width="83%"><input name="PatientID" type="text" id="ID" VALUE="<%= session.getAttribute( "Name" ) %>"></td>
                  </tr>
                </table></td>
              </tr>
            </table>
            <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
              <tr>
                <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                        <td width="17%"><strong>First Name:</strong></td>
                    <td width="83%"><input name="PatientFirstname" type="text" id="PatientFirstname" value="<%=rs.getString("PatientFirstName")%>"></td>
                  </tr>
                </table>
0
act1ve
Asked:
act1ve
  • 3
  • 2
1 Solution
 
bloodredsunCommented:
>> Think there is a problem with setting a variable equal the value of session variable. I am gettinmg the following problem

Doubtful, if the variable has a different name then it doesn't matter. You must cast it.

String user  = (String)session.getAttribute( "Name" ) ;

I'd be more interested in checking for syntax errors like missing brackets, <%%> and quotes if this doesn't solve it.

0
 
bloodredsunCommented:
Although, it's normally best to work on errors from the first to last. Looking at the error output, I think you are missing a } somewhere, possibly at the end of your "while" clause.
>>G:\Apache\work\Standalone\localhost\_\sad\updatetry$jsp.java:132: '}' expected.
>>}

And that this is causing your app to fall over and also causing the apparent problem with the try/catch statement.
0
 
act1veAuthor Commented:
nice one saw mistake but just quick question. I have my values showing in text fields except for drop down value is still default one. how can you set the  value of it equal the one in database?

Code:

 <td width="83%"><Select name="PatientGender" id="PatientGender" value="<%=rs.getString("PatientGender")%>">
                                    
                                    <option>Select...</option>
                                    <option value="F">F</option>
                                    <option value="M">M</option>
                                    </select>
                                    </td>
0
 
act1veAuthor Commented:
say if value = m in database i want it to show as m in field when viewing details, but using the above code it is only showing select....
0
 
bloodredsunCommented:
use an if statement

if (rs.getString("PatientGender").equals("F") ){
out.println("<option value=\"F\" selected=\"selected\">F</option>") ;
}else{
out.println("<option value=\"F\">F</option>") ;
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now