• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I M NOT ABLE TO DEFINE VARIABLES IN JSP.

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I M NOT ABLE TO DEFINE VARIABLES IN JSP.
I DEFINED USERTYPE/DESC BUT I M NOT ABLE ACCESS RESULTSET INTO THESE VARIABLES.
the code is as under
<%@ page language="java" session="true" import="java.sql.*" errorPage="err.jsp"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>

<%!
int UserTypeId;
int UserType;
String Desc;
%>
<html>
<html><head><title>Update User</title></head>
<body >
<b><h2><center>Update User</center></h2>

<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc dbc :p ts";

Connection con1=DriverManager.getConnection(url, "sa", "");
Statement stmt1 = con1.createStatement();

String qry="select u.* ,ut.usertypeid,ut.description from userinfo u , user_type ut where u.usertype=ut.usertypeid and u.userid="+ request.getParameter("UserId");

ResultSet rs1= stmt1.executeQuery(qry);

rs1.next();



%>
<center>
<table border="0" width="400" >
<tr>
<td width="100%" colspan="4" bgcolor="FF9999">
<p align="center"><font face="Verdana"><b>Update User Information</b></font></td>
</tr>
<tr>
<td width="100%" colspan="4"><font face="Verdana"><b> </b></font></td>
</tr>
<tr bgcolor="CCCCFF">

<td width="37%" align="right" colspan="2" ><font face="Verdana" size="2"><b>Name</b></font></td>
<td width="63%" colspan="2"><input type="text" name="Name" size="20" VALUE=<%=rs1.getString("Name")%>>
</tr>
<tr bgcolor="CCCCFF">

<td width="37%" align="right" colspan="2" ><font face="Verdana" size="2"><b>LoginName</b></font></td>
<td width="63%" colspan="2"><input type="text" name="UserName" size="20" VALUE=<%=rs1.getString("LoginName")%>>

</tr>

<tr bgcolor="CCCCFF">

<td width="37%" align="right" colspan="2" ><font face="Verdana" size="2"><b>Password</b></font></td>
<td width="63%" colspan="2"><input type="text" name="Password" size="20" VALUE=<%=rs1.getString("Password")%>>

</tr>
<tr bgcolor="CCCCFF">
<td width="37%" align="right" colspan="2"><font face="Verdana" size="2"><b>User Type</b></font></td>
<td width="63%" colspan="2"><%

%>
<select size="1" name="UsertypeID">
<%
Connection con2=DriverManager.getConnection(url, "sa", "");

Statement stmt2 = con2.createStatement();
String qry2="Select * from User_Type";

ResultSet rs2= stmt2.executeQuery(qry2);

while(rs2.next()){

Desc=request.getParameter("UserType");
int Desc1=Integer.parseInt(Desc);
//HERE 'S THE PROBLEM
UserType=rs2.getInt("UserTypeId");

%>

<option value=<%=rs2.getInt("UserTypeId")%>><%=rs2.getString("Description")%></option>
<%
}%>
</select></td>
</tr>
<tr>
<td width="23%" align="center"></td>
<td width="14%" align="center"><input type="submit" value="Save" name="Mode"></td>
<td width="18%" align="center"><input type="SUBMIT" value="Cancel" name="Mode"></td>
<td width="45%" align="center"></td>
</tr>
</table>
</center>
<%
rs1.close();
con1.close();




}
catch (Exception e) {}

//
%>
</body>
</html>

ps:
Disabled the smiles in the post.
- satya
[ January 12, 2002: Message edited by: Madhav Lakkapragada ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You present an awful lot of code but you don't say what happens. Does it throw an exception, fail to compile, get an illegal value???
Many people prefer to put code like this into a Javabean that can be tested separately. The JSP environment is difficult to debug.
Bill
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic