关于javabean的用法,为什么出错?(100分)

  • 主题发起人 主题发起人 jbas
  • 开始时间 开始时间
J

jbas

Unregistered / Unconfirmed
GUEST, unregistred user!
没有办法,还有错误,javabean怎么用?
TSystemAction.java文件
//系统操作包
package com.beltino.jbas.jforum.jmain;
import java.sql.*;
import java.util.*;
import java.io.*;
import com.beltino.jbas.jforum.util.*;
public class TSystemAction{
//private Connection conn;

//连接数据库
//public TSystemAction(){
// this.conn=DataBaseConnection.getConnection();
//}
//用户验证
public String checkUser(){
//System.out.println("User: " + User);
//System.out.println("Pwd: " + Pwd);
// Statement stmt=conn.createStatement();
//String sql;
// sql="select * from TUser";
// sql=sql+" where UserName='"+User+"' and UserPwd='"+Pwd+"'";
// ResultSet rst=stmt.executeQuery(sql);
// if (rst.next())
return "true";
// else
// return false;
}
}
////checkuser.jsp
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<jsp:useBean id="sysaction" scope="page" class="com.beltino.jbas.jforum.jmain.TSystemAction">
</jsp:useBean>
<%
String user=request.getParameter("user");
String pwd=request.getParameter("password");
out.println(user);
out.println(pwd);
String logined=sysaction.checkUser();
// boolean logined=false;
if (logined=="true"){
//session.setAttribute("sessionUserName",user);
//session.setAttribute("sessionUserPwd",pwd);
//session.setAttribute("sessionLogined","true");
out.println("myok");
//response.sendRedirect("index.jsp?logined=true");
}
else
{
out.println("false");
//response.sendRedirect("index.jsp?logined=false");
}
%>
提示错误:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: com.beltino.jbas.jforum.jmain.TSystemAction.checkUser()Ljava/lang/String;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.WebApp.CheckUser_jsp._jspService(CheckUser_jsp.java:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause
java.lang.NoSuchMethodError: com.beltino.jbas.jforum.jmain.TSystemAction.checkUser()Ljava/lang/String;
org.apache.jsp.WebApp.CheckUser_jsp._jspService(CheckUser_jsp.java:58)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

note The full stack trace of the root cause is available in the Tomcat logs.

--------------------------------------------------------------------------------
Apache Tomcat/5.0.16
帮忙了!
 
你不会是在记事本里写的代码吧???
我彻底晕菜:(
下面是帮你改的:
//系统操作包
package com.beltino.jbas.jforum.jmain;
import java.sql.*;
import java.util.*;
import java.io.*;
import com.beltino.jbas.jforum.util.*;
public class TSystemAction {
private Connection conn;
//连接数据库
//public TSystemAction(){
// this.conn=DataBaseConnection.getConnection();
//}
//用户验证
public String checkUser(String User, String Pwd) {
System.out.println("User: " + User);
System.out.println("Pwd: " + Pwd);
Statement stmt = null;
ResultSet rst = null;
try {
stmt = conn.createStatement();
String sql = "select * from TUser";
sql = sql + " where UserName='" + User + "' and UserPwd='" + Pwd + "'";
rst = stmt.executeQuery(sql);
if (rst.next()) {
return "true";
}
else
{
return "false";
}
}
catch (Exception ex) {
return "false";
}
finally {
try {
stmt.close();
rst.close();
}
catch (Exception ex) {
return "true";
}
}
}
}
 
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<jsp:useBean id="sysaction" scope="application" class="com.beltino.jbas.jforum.jmain.TSystemAction">
</jsp:useBean>
<%
String user=request.getParameter("user");
String pwd=request.getParameter("password");
out.println(user);
out.println(pwd);
String logined=sysaction.checkUser(user,pwd);
// boolean logined=false;
if (logined.equals("true")){
session.setAttribute("sessionUserName",user);
session.setAttribute("sessionUserPwd",pwd);
session.setAttribute("sessionLogined","true");
System.out.println("myok");
response.sendRedirect("index.jsp?logined=true");
}
else
{
System.out.println("false");
response.sendRedirect("index.jsp?logined=false");
}
%>

to 楼主,看来你对jsp+javabean的了解还不够多,继续努力学习:)
 
to lnboy
谢谢了,我改这个该死的东西很久,都不行了,还想要放弃了,气死我了,后来原来改了javabean后要重起Tcomcat,现在我加了reloadable="true"应该好了!
我刚学jsp,上次也谢谢你给我那个apache的dll文件,碰到高手了,多多指点呀。
您用什么写jsp and java,推荐一下了,万分感谢了!
 
你自己检查一下你自己的程序,就会发现你犯了不少很基本的错误。
//比如 返回 类型是 String的,你居然写 return false,呵呵:)
java的开发工具很多,
Jcreator,Jbuilder,Eclipse,IDEA,Jdeveloper。
其中Eclipse和Jdeveloper是免费的。
功能都很强大,你都可以先试用一下,最后再决定用哪一个。
千万不要说我是什么高手,只能够说可能比早接触jsp和java,
了解的可能比你多一点点而已。
建议多上网找点资料看看,调试些例子。
 
您谦虚了,我还想问一个问题,每次我编译了那个javabean,都得把它考到那个class目录下,太麻烦了,但如果把那个java原文件也放到class目录下,虽然编译完以后,那个class是放到了class目录下,不用再拷了,但是当我在另一个类中导入这个这个类时,会找不到 这个java类,不知您是怎样解决的,谢谢了!
 
把那个路径加到你的classpath里。
比如E:/jb/BeanServletTest/classes/com/delphibbs/TestClass.class
如果我想使用com.delphibb.TestClass.class
把E:/jb/BeanServletTest/classes加到 classpath里:
假设TestClass.class里有main方法,那么我运行命令:
d:/j2sdk1.42_02/bin/java -classpath "E:/jb/BeanServletTest/classes" com.delphibbs.TestClass
就可以运行我的class了。
 
我的以不能连数据库,你帮我再看看,谢谢了!
//系统操作包
package com.beltino.jbas.jforum.jmain;
import java.sql.*;
import java.util.*;
import java.io.*;
import com.beltino.jbas.jforum.util.*;
public class TSystemAction{
private Connection conn;

//连接数据库
public TSystemAction(){
this.conn=DataBaseConnection.getConnection();
}
//用户验证
public boolean checkUser(String User,String Pwd) throws Exception{
System.out.println("User: " + User);
System.out.println("Pwd: " + Pwd);
Statement stmt=conn.createStatement();
String sql;
sql="select * from TUser";
sql=sql+" where UserName='"+User+"' and UserPwd='"+Pwd+"'";
ResultSet rst=stmt.executeQuery(sql);
if (rst.next())
return true;
else
return false;
}
}
---------
//连接数据库包
package com.beltino.jbas.jforum.util;
import java.sql.*;
public class DataBaseConnection
{
public static Connection getConnection()
{
Connection con=null;
String SqlDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String SqlJdbc="jdbc.microsoft.sqlserver://localhost:1433;DatabaseName=jforum";
String User="sa";
String Pwd="btn";
try
{
Class.forName(SqlDriver);
con=DriverManager.getConnection(SqlJdbc,User,Pwd);
}
catch(Exception e)
{
e.printStackTrace();
}
return con;
}
}
 
错误提示:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause
java.lang.NullPointerException
com.beltino.jbas.jforum.jmain.TSystemAction.checkUser(TSystemAction.java:19)
org.apache.jsp.WebApp.CheckUser_jsp._jspService(CheckUser_jsp.java:58)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

note The full stack trace of the root cause is available in the Tomcat logs.
 
jdbc 的sqlserver连接的三个文件,我放到了:
E:/Tomcat5/common/lib
 
checkuser.jsp
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<jsp:useBean id="sysaction" scope="session" class="com.beltino.jbas.jforum.jmain.TSystemAction">
</jsp:useBean>
<%
String user=request.getParameter("user");
String pwd=request.getParameter("password");
out.println(user);
out.println(pwd);
boolean logined=sysaction.checkUser(user,pwd);
if (logined==false){
//session.setAttribute("sessionUserName",user);
//session.setAttribute("sessionUserPwd",pwd);
//session.setAttribute("sessionLogined","true");
out.println("true");
//response.sendRedirect("index.jsp?logined=true");
}
else
{
out.println("false");
//response.sendRedirect("index.jsp?logined=false");
}
%>
 

<%
String user="";
if (request.getParameter("user")!=null) {
user=request.getParameter("user");
}
String pwd="";
if (request.getParameter("password")!=null) {
pwd= request.getParameter("password")
}
 
谢谢了,我已经解决了,但好象也不太清楚是为什么,昨天死活不行,今天好象又行了,昨天也重启了Tomcat好几遍。真是不懂,以后请多多指教。
 
后退
顶部