HI vansh..
I yest got jsp:useBean working...so i think i can help u out correctly....test the below code..once u get to know how it is working u can then work on complex codes
This is javabean class
SimpleBean.java
package com.test;
public class SimpleBean implements java.io.Serializable {
/* Properties */
private String name = null;
private int age = 0;
/* Empty Constructor */
public SimpleBean() {}
/* Getter and Setter Methods */
public String getName() {
return name;
}
public void setName(String s) {
name = s;
}
public int getAge() {
return age;
}
public void setAge(int i) {
age = i;
}
}
now create a folder for package.... ie in ur c:\ create com folder n inside tht create test folder n place this SimpleBean.java file in it...if u know how package works this will b easy for u...
n then on command prompt set classpath for ur package
ie c:\>set classpath=,;c:\com;
now compile the SimpleBean.java
ie c:\com\test>javac SimpleBean.java
if everything is fine u wont get error....
now if u r using tomcat then go to webapps/root/web-inf/classes... inside classes u need to create same folder structure tht u created in C:\.. ie inside classes create com folder n inside tht create test folder and now copy ur SimpleBean.class file inside test folder
then place below testbean.jsp file in ur webapps/root folder of tomcat...
testbean.jsp
<html>
<head>
<title>SimpleBean Test Page</title>
</head>
<body>
<%-- Creating JavaBeans --%>
<jsp:useBean id="simple" class="com.test.SimpleBean">
<jsp:setProperty name="simple" property="name" value="hetal" />
<jsp:setProperty name="simple" property="age" value="00" />
</jsp:useBean>
<%-- Displaying JavaBean property's value --%>
Name retrieved from JavaBean has the value of :
<b><jsp:getProperty name="simple" property="name" /></b>.<br>
Age retrieved from JavaBean has the value of :
<b><jsp:getProperty name="simple" property="age" /></b> years.<br>
</body>
</html>
this should definitely work for u.........
Good luck.
Use JDBC.
You can find the JDBC tutorial here: http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html
And the MySQL JDBC driver here: http://www.mysql.com/products/connector/j/
Finally the MySQL driver reference: http://dev.mysql.com/doc/refman/5.0/en/connector-j.html
Hi vansh,
here is the example of session...
wotever you want into session u need to add tht into session first like
String username="abcxyz";
session.setAttribute("user",username);
in jsp u can directly use the session object ie session...and setAttribute() is the method to set content for session.... now "user" is the session name give to ur variable "username"....n u will access session content using this name...like
session.getAttribute("user");
hope u r able to get it.....
Here is wot i found out for session...n sorry for previous reply...
coz i m totally messed up between javabean and JSTL...
http://forum.java.sun.com/thread.jspa?threadID=518448&messageID=2474374
i tried out n it works fine..in tht program they have not used setProperty n getProperty...they have called method directly...
here is my previous code with session...
testbean.jsp
<html>
<head>
<title>SimpleBean Test Page</title>
</head>
<body>
<%-- Creating JavaBeans --%>
<jsp:useBean id="simple" scope="session" class="com.test.SimpleBean">
<jsp:setProperty name="simple" property="name" value="hetal giri" />
<jsp:setProperty name="simple" property="age" value="21" />
</jsp:useBean>
<%-- Displaying JavaBean property's value --%>
Name retrieved from JavaBean has the value of :
<b><jsp:getProperty name="simple" property="name" /></b>.<br>
Age retrieved from JavaBean has the value of :
<b><jsp:getProperty name="simple" property="age" /></b> years.<br>
<A href="page2.jsp">Continue</A>
</body>
</html>
page2.jsp
<html>
<head><title></title></head><body>
<jsp:useBean id="simple" scope="session" class="com.test.SimpleBean">
</jsp:useBean>
<jsp:getProperty name="simple" property="age" />
<%
int beanInt = simple.getAge();
%>
<%= "beanInt = " + beanInt %>
</body></html>
enjoy..............