• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to import two package in jsp?  RSS feed

 
Sudhakar Gaharwar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1>In third line of below program i am importing sql package and suppose again i want to import util package then how can i do this in same line without using new directive tag.

2>In 25th line i am establishing the connection in scriptlet tag.So Is there any place in jsp like servlet init method where we can do the work of establishing the connection etc...(i know in bean we can do that)..

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

<font size=6>
<% String s1=request.getParameter("un");
if(s1==null)
{
%>
<form>
Enter User Name:
<input type=text name="un">
<br>
<input type=password name="pwd">
<input type=submit value="CHECK">
</form>

<%
}
else
{
try{
s1=s1.trim();
s2=s2.trim();

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc eepu","scott","tiger");
PreparedStatement ps=con.prepareStatement("select username,password from secure where username=? and password=?");
ps.setString(1,username);
ps.setString(2,password);
ResultSet rs=ps.executeQuery();
out.println("<font size=6>");
while(rs.next())
{
username=rs.getString(1);
password=rs.getString(2);
}
if (username.equals("un") && password.equals("pwd"))
out.println("<br>Login Successful");
ps.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);}
}
%>

</font>
</body>
</html>
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write , although it is considered bad design to perform SQL operations in JSP pages.

As to initializations: they're called declarations in JSPs, and look something like this . The JSP specification tells you more about them.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!