View: 2150|Reply: 10
|
error dlm Java servlet&JavaBean..tlg solve kan..plsss
[Copy link]
|
nur_imann This user has been deleted
|
saper-saper bleh tolong tgkkan error nih..aper maksud dia ye?
dpt error mcm nih..
LoginServlet5.java:28:cannot resolve symbol
symbol: class LoginBean
location : class project1.LoginServlet5
LoginBean lb = new LoginBean();
^
LoginServlet5.java:28:cannot resolve symbol
symbol: class LoginBean
location : class project1.LoginServlet5
LoginBean lb = new LoginBean();
^
2 errors |
|
|
|
|
|
|
|
macam salah board je nih...
kalo ye pon bagi la the whole coding nye...
camne nak detect kalo ko bagi errors je...adeh |
|
|
|
|
|
|
|
Thread moved to Programming & Networking Board. |
|
|
|
|
|
|
|
class LoginBean dah create?
class LoginBean dah include dalam classpath?
class LoginBean dah import dalam your source code?
[ Last edited by shahnazz at 25-7-2007 02:42 PM ] |
|
|
|
|
|
|
nur_imann This user has been deleted
|
ops..eh salah board ker..adehh..hehhehe..sory arr org_letrik.
ni utk org letrik..
directory utk file nih...C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\project\WEB-INF\classes\project1..
coding for LoginServlet5.java..
package project1;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* This servlet simply prints out HTTP method name and query string in it's service method.
*
*/
public class LoginServlet5 extends HttpServlet
{
//If somebody types up the URL for this servlet
//in the address field of the browser.
public void doGet(HttpServletRequest req, HttpServletResponse res) throws javax.servlet.ServletException, java.io.IOException
{
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws javax.servlet.ServletException, java.io.IOException
{
String userid = req.getParameter("userid");
String password =req.getParameter("password");
if(userid != null && password != null )
{
LoginBean lb = new LoginBean();
boolean verified = lb.checkPassword(userid,password);
if (verified)
{
//set userid in request to pass it on to AccountServlet
req.getRequestDispatcher("/jspFiles/homepage.jsp").forward(req, res);
}
else
{
//userid,password verified. Forward request to AccountServlet.
//observe the use of absolute path.
req.getRequestDispatcher("/jspFiles/login2.html").forward(req, res);
return;
}
}
else
{
//Unable to login. Send login.html to the user.
//observe the use of relative path.
req.getRequestDispatcher("/jspFiles/login2.html").forward(req, res);
return;
}
}
}
------------------------------------------------------------------------------------------------------------
ni plk untk codin LoginBean.java
directory utk file nih..
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\project\WEB-INF\classes\beans
package beans;
import java.sql.*;
import java.io.*;
public class LoginBean
{
String dbURL;
String dbDriver="sun.jdbc.odbc.JdbcOdbcDriver";
private Connection conn;
Statement stmt;
ResultSet rs;
public LoginBean() {}
public boolean checkPassword(String userid,String password)
{
try{
String sql = "SELECT "+userid+" , "+password+" FROM Users";
connect();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if((rs !=null))
return true;
else
return false;
}
catch(Exception e)
{e.getMessage();}
return false;
}
public boolean connect() throws ClassNotFoundException,SQLException
{
Class.forName(getDbDriver());
conn=DriverManager.getConnection("jdbc.odbc.EmpDetails","","");
return true;
}
public ResultSet executeSQL(String sql) throws SQLException
{
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
if((rs==null))
return null;
else
return rs;
}
public String getDbDriver()
{
return dbDriver;
}
public void setDbDriver(String newVal)
{
dbDriver=newVal;
}
public String getDbURL()
{
return dbURL;
}
public void setDbURL(String newVal)
{
dbURL=newVal;
}
public void close()throws SQLException
{
conn.close();
}
}
thank you for advance... |
|
|
|
|
|
|
|
setkan CLASSPATH ...
cth set CLASSPATH=%CLASSPATH%;C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\project\WEB-INF\classes
lepas tu mula compile
mulakan dari directory
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\project\WEB-INF\classes\beans
javac *.java
lepas tu compile file dalam directory
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\project\WEB-INF\classes\project1
javac *.java |
|
|
|
|
|
|
nur_imann This user has been deleted
|
utk ultra78..
classpath dah set dah..point to:--->>
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\project\WEB-INF\classes\
btul ker? |
|
|
|
|
|
|
nur_imann This user has been deleted
|
moderetor,....Terima kasih ye moved kan problem tu dlm board nih..
for your questions....
class LoginBean dah create?
class LoginBean dah include dalam classpath?
class LoginBean dah import dalam your source code?
dah buat dah semua tu...
anyway,thanks ya' |
|
|
|
|
|
|
|
Dekat file LoginServlet5.java tuh import sekali beans....pasal yg first tuh dlm package project1 yg lagi satu lak dlm package beans...That why error dia tulis "cannot resolve symbol"..dia tak jumpa class LoginBean dlm package beans tuh...hope can help u |
|
|
|
|
|
|
|
packagekan folder beans jadi beans.jar. then masukkan dlm ...WEB-INF/lib/ jadi mcm ni -> C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\project\WEB-INF\lib\beans.jar. Pas tu kat kawasan import ko tu, tambah line ni -> import beans.*;
pas tu compile. jgn lupa masa compile tu setkan classpath C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\project\WEB-INF\lib\beans.jar
tapikan senang klu ko pakai JAVA IDE editor mcm netbeans / ECLIPSE. senang nak compile. Buat coding pun senang.. |
|
|
|
|
|
|
| |
|