Where put .class file using jsp+javabean?
[nobr]I create a javabean named "DbBean.java",
create two asp files called "db.jsp" and "connect.jsp"
but where should I put compiled DbBean.class.
I just use text-code file. no other tools.
Following is the code:
--
db.jsp
<html>
<title>
</title>
<body>
<div align=center>
<form action="connect.jsp" method="get">
<table border=3 cellspacing=3>
<tr><td>DB Name丗</td><td><input type="text" name="dbname"></td></tr><br>
<tr><td>URL: </td><td><input type="text" name="url"></td></tr><br>
<tr><td>driver: </td><td><input type="text" name="driver"></td></tr><br>
<tr><td>User Name: </td><td><input type="text" name="username"></td></tr><br>
<tr><td>Password: </td><td><input type="password" name="password"></td></tr><br>
</table>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</div>
</table>
</body>
</html>
connect.jsp
<%@page contentType="text/html" language="java" import="java.sql.*"%>
<!--Connect mysql-->
<html>
<body>
<jsp:useBean id="connect" scope="page" class="dbBean.DbBean" />
<%
String name=request.getParameter("name");
String password=request.getParameter("password");
connect.setDbName(name);
connect.setPass(password);
connect.BuliCon();
connect.updateLog("insert into a1 values (10,"fuck");");
%>
<br>Hello</br>
</body>
</html>
[/nobr]
[2595 byte] By [
withgogoa] at [2007-10-2 14:24:44]

Here is your use bean statement
<jsp:useBean id="connect" scope="page" class="dbBean.DbBean" />
Because you have class="dbBean.DbBean, the actual class file DbBean.class should go in the WEB-INF/classes/dbBean folder. Also, at the top of you DbBean.java file you should have
package dbBean;
publilc class DbBead {
...
}
yes, sure I have put the top package.
But I really don't understand where is this "WEB-INF" folder.
Is it a folder named "WEB-INF"?
Or, it is a folder where I put my jsp files?
the following is the DbBean.java code
package dbBean;
import java.sql.*;
public class DbBean {
private String DbName = "";
private String pass = "";
private String urlPart="";
private String url = "";
private String user="";
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
public DbBean()
{
}
public void setDbName (String name)
{
this.DbName = name;
}
public void setPass (String pass)
{
this.pass = pass;
}
public void setUrl(String url)
{
this.urlPart=url;
}
public void setUser(String user)
{
this.user=user;
}
public void BulidCon()
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
url =urlPart+DbName+"?user="+user+"&password="+pass;
con= DriverManager.getConnection(url);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
catch (Exception e)
{
}
}
public ResultSet selectLog(String sql)
{
try
{
BulidCon();
rs = stmt.executeQuery(sql);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return rs;
}
public void updateLog(String sql)
{
try
{
BulidCon();
stmt.executeUpdate(sql);
}
catch (Exception e)
{
}
}
public void close()
{
try
{
con.close();
stmt.close();
}
catch (SQLException e)
{
}
}
}
> yes, sure I have put the top package.
> But I really don't understand where is this "WEB-INF"
> folder.
> Is it a folder named "WEB-INF"?
> Or, it is a folder where I put my jsp files?
> the following is the DbBean.java code
You will be well suited to read some book, or at least a tutorial, on Servlet deployment and Web Applications.
The WEB-INF directory is one of the most important parts of the web application. Learning how to use it is necessary.
You have the root of your web application, called the Servlet Context. Generally it is a directory under your server's 'webapps' directory with the name of the application:
%ServerHome%/webapps/MyApplication/
That is generally where you put your JSPs.
%ServerHome%/webapps/MyApplication/
index.jsp
some.jsp
This is also the directory where your WEB-INF goes:
%ServerHome%/webapps/MyApplication/
index.jsp
some.jsp
WEB-INF/
The WEB-INF should contain the classes directory which holds the packages of classes your app uses, as well as your web.xml (very important to learn what this is!!) and a lib directory to hold JAR files. Any other resources your web application uses should also go in here:
%ServerHome%/webapps/MyApplication/
index.jsp
some.jsp
WEB-INF/
web.xml
classes/
dbBean/
DbBean.class
lib/
MySQLDriver.jar
u mean the wwwroot where I set in IIS is the Server Home?If there is no WEB-INF directory, then I create it, will it work?
> u mean the wwwroot where I set in IIS is the Server
> Home?
I know nothing of IIS. Figure out where your Servlet Context begins, and work from there. Read your Server's documents.
> If there is no WEB-INF directory, then I create it,
> will it work?
It should.
Hello, I downloaded J2EE.
Can I setup the environment can run this Javabean and jsp pages without any Tomcat or some others. I searched a lot in Internet, most of them are talking about how to use Tomcat to do this.
Read a lot about J2EE, but still don't know where should I put the .class file and make jsp work.
Thx a lot!
Sun's J2EE is a bit more automated/complicated than Tomcat.
Actually I think they use Tomcat under the hood to provide the servlet/jsp engine.
You use their deploytool to bundle a WAR and deploy it.
Their tutorial demonstrates it.
Personally I don't like the deploy tool, and prefer using Tomcat / JBoss where I know how things are configured, rather than let some process do it for me.