当前位置: 技术问答>java相关
调用bean和jsp的问题?
来源: 互联网 发布时间:2015-10-17
本文导语: 我做了一个findbean.java和一个look_up.jsp findbean.java的源程序如下: package find; import java.sql.*; public class FindBean{ private boolean success; //查找是否成功 private String answer; //查找到的答案 private int par; //参数的状态,0为...
我做了一个findbean.java和一个look_up.jsp
findbean.java的源程序如下:
package find;
import java.sql.*;
public class FindBean{
private boolean success; //查找是否成功
private String answer; //查找到的答案
private int par; //参数的状态,0为非法状态
public FindBean(){
reset();
}
public void setNum(String num){
int g;
try{
g=Integer.parseInt(num);
par=g;
}catch(NumberFormatException e){
par=-1;
}
}
public String getAnswer(){
String s1="";
try{
String url="jdbc:odbc:look";
String user="";
String pws="";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url,user,pws);
Statement s=c.createStatement();
String sql="select name from java where id="+par;
ResultSet r=s.executeQuery(sql);
while(r.next()){
s1=r.getString("name");
}
}catch(Exception e){
System.out.println(e.getMessage());
}
return s1;
}
public void reset(){
success=false;
answer="";
par=0;
}
public boolean getSuccess(){
return success;
}
public int getPar(){
return par;
}
}
look_up.jsp的源程序如下:
Untitled Document
我装的是jbuilder7,配置已经完成,配置是这样的:系统变量TOMCAT_HOME 值D:JBuilder7jakarta-tomcat-4.0.3
系统变量JAVA_HOME 值d:jdk1.3.0_02
我该怎样调用findbean.java和look_up.jsp?
findbean.java的源程序如下:
package find;
import java.sql.*;
public class FindBean{
private boolean success; //查找是否成功
private String answer; //查找到的答案
private int par; //参数的状态,0为非法状态
public FindBean(){
reset();
}
public void setNum(String num){
int g;
try{
g=Integer.parseInt(num);
par=g;
}catch(NumberFormatException e){
par=-1;
}
}
public String getAnswer(){
String s1="";
try{
String url="jdbc:odbc:look";
String user="";
String pws="";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url,user,pws);
Statement s=c.createStatement();
String sql="select name from java where id="+par;
ResultSet r=s.executeQuery(sql);
while(r.next()){
s1=r.getString("name");
}
}catch(Exception e){
System.out.println(e.getMessage());
}
return s1;
}
public void reset(){
success=false;
answer="";
par=0;
}
public boolean getSuccess(){
return success;
}
public int getPar(){
return par;
}
}
look_up.jsp的源程序如下:
Untitled Document
请输入人员座位号:
我装的是jbuilder7,配置已经完成,配置是这样的:系统变量TOMCAT_HOME 值D:JBuilder7jakarta-tomcat-4.0.3
系统变量JAVA_HOME 值d:jdk1.3.0_02
我该怎样调用findbean.java和look_up.jsp?
|
直接在ie里敲look_up.jsp的地址就行了
|
在jbuilder里建个工程,把这2个文件都放进去,直接运行就可以了!不会放的话,新建一个类一个jsp文件,把代码考过去就可以了!