jsp+weblogic7(100分)

  • 主题发起人 主题发起人 月如钩
  • 开始时间 开始时间

月如钩

Unregistered / Unconfirmed
GUEST, unregistred user!
我在学JSP,我装了JDK1.3.1,weblogic7和SQLSERVER,可是我不会配置,请教详细配置过程,呵呵,我是菜鸟,请说得具体一点,万分感谢!
 
weblogic7自己有JDK,不用配置;
把你用的JSP文件放到:盘符+
/bea/wlserver6.1/config/mydomain/applications/DefaultWebApp目录下就可运行,不过应该先把weblogic7服务器启动起来;
使用SQL SERVER可以有几种方式,最简单的是在JSP页面中嵌入JDBC的调用代码,如:<%
String DriverName="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(DriverName);
Connection cn=DriverManager.getConnection("Jdbc:odbc:bookstore","sa","goodat");
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
%>
在WEBLOGIC中还有其它方式,我把我知道的经过验证的代码依次贴出来了:
<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="java.util.*"%>
<html>
<head>
<title>用JDBC:ODBC获取池连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
String driverName="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driverName);
String driverURL="jdbc:odbc:bookstore";
Connection cn=DriverManager.getConnection(driverURL,"sa","goodat");

//另一种连接方式
//String driverURL="jdbc:weblogic:pool:JdbcOdbc";
//Connection cn=myDriver.connect(driverURL,null);
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%

}
rs.close();
stmt.close();
cn.close();
%>
</body>
</html>

<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="javax.naming.*"%>
<html>
<head>
<title>通过JNDI查找数据源连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
javax.sql.DataSource myDataSource=null;
try{
Context myContext=new InitialContext();
myDataSource=(javax.sql.DataSource)myContext.lookup("JdbcOdbcDS");
try{
Connection cn=myDataSource.getConnection();
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
cn.close();
}catch(SQLException e){
e.toString();
}
}catch(NamingException e){
e.toString();
}

%>
</body>
</html>

<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="javax.naming.*"%>
<html>
<head>
<title>通过JNDI查找多池连接的数据源连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
javax.sql.DataSource myDataSource=null;
try{
Context myContext=new InitialContext();
myDataSource=(javax.sql.DataSource)myContext.lookup("MultiPoolDS");
try{
Connection cn=myDataSource.getConnection();
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
cn.close();
}catch(SQLException e){
e.toString();
}
}catch(NamingException e){
e.toString();
}

%>
</body>
</html>

<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="java.util.*"%>
<html>
<head>
<title>从WEBLOGIC池驱动程序获取池连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
String driverName="weblogic.jdbc.pool.Driver";
Driver myDriver=(Driver)Class.forName(driverName).newInstance();

String driverURL="jdbc:weblogic:pool";
Properties myProperties=new Properties();
myProperties.put("connectionPoolID","JdbcOdbc");
Connection cn=myDriver.connect(driverURL,myProperties);

//另一种连接方式
//String driverURL="jdbc:weblogic:pool:JdbcOdbc";
//Connection cn=myDriver.connect(driverURL,null);
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%

}
rs.close();
stmt.close();
cn.close();
%>
</body>
</html>

<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="java.util.*"%>
<html>
<head>
<title>从WEBLOGIC的多连接池驱动程序获取池连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
String driverName="weblogic.jdbc.pool.Driver";
Driver myDriver=(Driver)Class.forName(driverName).newInstance();

String driverURL="jdbc:weblogic:pool";
Properties myProperties=new Properties();
myProperties.put("connectionPoolID","MyJDBC MultiPool");
Connection cn=myDriver.connect(driverURL,myProperties);

//另一种连接方式
//String driverURL="jdbc:weblogic:pool:JdbcOdbc";
//Connection cn=myDriver.connect(driverURL,null);
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%

}
rs.close();
stmt.close();
cn.close();
%>
</body>
</html>
请参考。
 

Similar threads

D
回复
0
查看
867
DelphiTeacher的专栏
D
D
回复
0
查看
836
DelphiTeacher的专栏
D
D
回复
0
查看
785
DelphiTeacher的专栏
D
D
回复
0
查看
909
DelphiTeacher的专栏
D
D
回复
0
查看
704
DelphiTeacher的专栏
D
后退
顶部