• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use Usebean Tag and setProperty and getProperty

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am trying to use Usebean tag to retive data from the data base and print in the jsp.

to get connection:

import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import com.osi.db.*;


public class Details {
public SearchForm search(String pid)throws Exception{
SearchForm sf = null;
try {
Connection connection = DBConnection.getConnection();
System.out.println("Connection to DB");
String query = "select * from product where prodId="+pid;
// prodId="+pid AND price=price AND prodName LIKE '%prodName%'
// prodId="+pid OR price=price OR prodName LIKE '%prodName%'
// prodId="+pid OR price=price OR prodName=prodName'
ResultSet rs = null;
Statement stmt = null;
stmt =connection.createStatement();
rs = stmt.executeQuery(query);
System.out.println(rs);

while (rs.next()){
sf = new SearchForm();
sf.setProdId(rs.getString(1));
sf.setPrice(rs.getString(2));
sf.setProdName(rs.getString(3));
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
}
catch (Exception e){
System.out.println("Error while connecting to DB");
}
return sf;
}

}
search Form
package com.osi.search;

public class SearchForm {

private String prodId;
private String prodName;
private String price;


public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getProdId() {
return prodId;
}
public void setProdId(String prodId) {
this.prodId = prodId;
}
public String getProdName() {
return prodName;
}
public void setProdName(String prodName) {
this.prodName = prodName;
}

}

GETConnection;
package com.osi.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DBConnection {

public static Connection getConnection() throws SQLException {

Connection con =null;


try {

String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName);
String url = "jdbc:mysql://localhost:3306/mysql" ;
con = DriverManager.getConnection(url,"root","root");
System.out.println(con);
}

catch(Exception e)
{
System.out.println("unable to conncect to database");
}
return con;
}}




Bean Jsp:


<%@ page language="java" import="java.util.*"%>
<%@ page language="java" import="com.osi.search.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SimpleBean Test Page</title>
</head>
<body>

<%-- Creating JavaBeans --%>
<%Details d = new Details();
// SearchForm f = new SearchForm();
String pid =request.getParameter("prodId");
System.out.println(pid);
SearchForm frm = d.search(pid);
out.println("****************");
out.println(frm.getProdId()); /here i am able to get the values
out.println(frm.getPrice()); .......
%>

<jsp:useBean id="search" beanName="frm" type="com.osi.search.SearchForm" scope="page">

<jsp:setProperty name="search" property="prodId"/>
<jsp:getProperty name ="search" property="prodName"/>

</jsp:useBean>

<%= search.getPrice()%>

<%= search.getProdId()%>

<%= search.getProdName()%>


</body>
</html>

Can any one help me please ,I am unable to get the values printed when using usebean tag

------
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: frm
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.Bean_jsp._jspService(Bean_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


root cause

java.lang.InstantiationException: frm
org.apache.jsp.Bean_jsp._jspService(Bean_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810
Showing this error .
Thanks
Naveen
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naveen gandham wrote:
root cause
java.lang.InstantiationException: frm


To the point, the following failed gratefully:

Read the appserver logs (not the error page in webbrowser!) for more details and more stacktraces after that. There in you can find the root cause of the InstantiationException.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic