Prblems accessing a bean from JSP
From: dinesh prasad (dinesh__C__P_at_hotmail.com)
Date: 10/20/03
- Next message: Paul Lutus: "Re: how to get the path of my current class that running?"
- Previous message: Sudsy: "Re: Hashtable and Synchronization"
- Next in thread: Jon Martin Solaas: "Re: Prblems accessing a bean from JSP"
- Reply: Jon Martin Solaas: "Re: Prblems accessing a bean from JSP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 19 Oct 2003 23:31:45 -0700
Alright, I have tried a different design based on a template. The
controller servlet dispenses the JSPs and the dataBean stores values
into the database.
I haven't gotten to the display servet yet, I just want to get the
values into the database to start wtih. Here is the error I get trying
to compile addPage.jsp
showPage$jsp.java [70:1] cannot resolve symbol
symbol : class dataBean
location: package burnaby
com.brainysoftware.burnaby.dataBean dbBean = null;
^
showPage$jsp.java [73:1] cannot resolve symbol
code:
package com.brainysoftware.burnaby;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.brainysoftware.burnaby.DbBean;
public class ControllerServlet extends HttpServlet {
/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException {
System.out.println("initializing controller servlet.");
ServletContext context = config.getServletContext();
context.setAttribute("base", config.getInitParameter("base"));
context.setAttribute("imageUrl",
config.getInitParameter("imageUrl"));
// instantiating the DbBean
DbBean dbBean = new DbBean();
// initialize the DbBean's fields
dbBean.setDbUrl(config.getInitParameter("dbUrl"));
dbBean.setDbUserName(config.getInitParameter("dbUserName"));
dbBean.setDbPassword(config.getInitParameter("dbPassword"));
// put the bean in the servlet context
// the bean will be accessed from JSP pages
context.setAttribute("dbBean", dbBean);
try {
// loading the database JDBC driver
Class.forName(config.getInitParameter("jdbcDriver"));
System.out.println(config.getInitParameter("jdbcDriver"));
}
catch (ClassNotFoundException e) {
System.out.println(e.toString());
}
super.init(config);
}
/**Process the HTTP Get request*/
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
doPost(request, response);
}
/**Process the HTTP Post request*/
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String base = "/jsp/";
String url = base + "Default.jsp";
String action = request.getParameter("action");
if (action!=null) {
if (action.equals("search"))
url = base + "SearchResults.jsp";
else if (action.equals("browseCatalog"))
url = base + "BrowseCatalog.jsp";
else if (action.equals("productDetails"))
url = base + "ProductDetails.jsp";
else if (action.equals("productDetails"))
url = base + "ProductDetails.jsp";
else if (action.equals("addShoppingItem") ||
action.equals("updateShoppingItem") ||
action.equals("deleteShoppingItem") ||
action.equals("displayShoppingCart"))
url = base + "ShoppingCart.jsp";
else if (action.equals("checkOut"))
url = base + "CheckOut.jsp";
else if (action.equals("order"))
url = base + "Order.jsp";
else if (action.equals("registerhomepage"))
url = base + "registeruser.jsp";
else if (action.equals("showThePage"))
url = base + "homepage.jsp";
else if (action.equals("templateprocessor"))
url = base + "templateprocessor.jsp";
else if (action.equals("login"))
url = base + "Login.jsp";
else if (action.equals("addPage"))
url = base + "showPage.jsp";
}
System.out.println(url);
RequestDispatcher requestDispatcher =
getServletContext().getRequestDispatcher(url);
requestDispatcher.forward(request, response);
}
}
templateprocessor.jsp
<jsp:useBean id="theBean" class="com.infologic" />
<jsp:setproperty name="theBean" property="Username"/>
<jsp:setproperty name="theBean" property="pass"/>
<jsp:setproperty name="theBean" property="maintitle"/>
<jsp:setproperty name="theBean" property="main"/>
<jsp:setproperty name="theBean" property="aboutustitle"/>
<jsp:setproperty name="theBean" property="aboutus"/>
<jsp:setproperty name="theBean" property="servicestitle"/>
<jsp:setproperty name="theBean" property="services"/>
<jsp:setproperty name="theBean" property="contactustitle"/>
<jsp:setproperty name="theBean" property="contactus"/>
<jsp:setproperty name="theBean" property="misctitle"/>
<jsp:setproperty name="theBean" property="misc"/>
<form method=post>
<td><input type="text" name="Username"
size="15" border="0"></td>
<jsp.getProperty name="theBean"
property="Username" />
<td><input type="password" name="pass" size=15
border="0"></td>
<jsp.getProperty name="theBean"
property="pass" />
<td><input type="text" name="maintitle" size=15
border="0"></td>
<jsp.getProperty name="theBean"
property="maintitle" />
<td><input type="text" name="main" size="10"
border="0"></td>
<jsp.getProperty name="theBean"
property="main" />
<td><input type="text" name="aboutustitle"
size="15" border="0"></td>
<jsp.getProperty name="theBean"
property="aboutustitle" />
<td><input type="text" name="aboutus" size="7"
border="0"></td>
<jsp.getProperty name="theBean"
property="aboutus" />
<td><input type="text" name="servicestitle"
size="10" border="0"></td>
<jsp.getProperty name="theBean"
property="servicestitle" />
<td><input type="text" name="services"
size=15 border="0"></td>
<jsp.getProperty name="theBean"
property="services" />
<td><input type="text"
name="contactustitle" size=15 border="0"></td>
<jsp.getProperty name="theBean"
property="contactustitle" />
<td><input type="text"
name="contactus" size=15 border="0"></td>
<jsp.getProperty name="theBean"
property="contactus" />
<td><input type="text"
name="misctitle" size=15 border="0"></td>
<jsp.getProperty name="theBean"
property="misctitle" />
<td><input type="text" name="misc"
size=15 border="0"></td>
<jsp.getProperty name="theBean"
property="misc" />
<input type="submit">
<input type="hidden" name="action"
value="addage">
</body>
</hmtl>
showPage.jsp
<%@page import="java.sql.*" %>
<%@page import="java.util.*" %>
<jsp:useBean id="dbBean" scope="application"
class="com.brainysoftware.burnaby.dataBean" />
<html>
<head><title></title></head>
<table>
<%
if(dbBean.insertPage(request.getParameter("Username"),
request.getParameter("pass"),
request.getParameter("maintitle"),
request.getParameter("main"),
request.getParameter("aboutus"),
request.getParameter("aboutustitle"),
request.getParameter("services"),
request.getParameter("servicestitle"),
request.getParameter("contactus"),
request.getParameter("contactustitle"),
request.getParameter("misc"),
request.getParameter("misctitle"))) {
session.invalidate();
}
else
System.out.println("error");
%>
<body>
Thank you.
<%
response.sendRedirect("http://localhost:7001/citylinks/Default");
%>
</body>
</html>
dataBean.class
import java.sql.*;
import java.io.*;
import java.util.*;
import java.lang.*;
public class dataBean {
private String Username="";
private String pass="";
private String maintitle="";
private String main="";
private String aboutustitle="";
private String aboutus="";
private String servicestitle="";
private String services="";
private String contactustitle="";
private String contactus="";
private String misctitle="";
private String misc="";
private int yes=1;
Connection dbConn = null;
public String getUsername() {
return Username;
}
public void setUsername(String Username) {
if (Username!=null)
this.Username = Username;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
if (pass!=null)
this.pass = pass;
}
public void setMaintitle (String maintitle) {
if (maintitle!=null)
this.maintitle = maintitle;
}
public String getMaintitle () {
return maintitle;
}
public void setAboutustitle(String aboutustitle) {
if (aboutustitle!=null)
this.aboutustitle = aboutustitle;
}
public String getAboutustitle() {
return aboutustitle;
}
public void setAboutus(String aboutus) {
if (aboutus!=null)
this.aboutus = aboutus;
}
public String getAboutus() {
return aboutus;
}
public void setServices(String services) {
if (services!=null)
this.services = services;
}
public String getServices() {
return services;
}
public void setServicestitle(String servicestitle) {
if (servicestitle!=null)
this.servicestitle = servicestitle;
}
public String getServicestitle() {
return servicestitle;
}
public void setContactus(String contactus) {
if (contactus!=null)
this.contactus = contactus;
}
public String getContactus() {
return contactus;
}
public void setMisc(String misc) {
if (misc!=null)
this.misc = misc;
}
public String getMisc() {
return misc;
}
public void setMisctitle(String misctitle) {
if (misctitle!=null)
this.misctitle = misctitle;
}
public String getMisctitle() {
return misctitle;
}
public boolean insertPage(String Username, String main, String
aboutus, String aboutustitle, String services, String servicestitle,
String contactus, String contactustitle, String misc, String
misctitle)
{
boolean returnValue=false;
// create a persistent conneciton to the SQL server
System.out.println("servlet started");
String jdbcDriver = "weblogic.jdbc.mssqlserver4.Driver";
String dbURL =
"jdbc:weblogic:mssqlserver4:freelance@COMPAQSERVER";
String usernameDbConn = "dinesh";
String passwordDbConn = "werty6969";
System.out.println("database info set up..");
try
{
Class.forName(jdbcDriver).newInstance();
dbConn = DriverManager.getConnection(dbURL,
usernameDbConn, passwordDbConn);
}
catch (ClassNotFoundException e)
{
// throw new UnavailableException("jdbc driver not
found:" + dbURL);
}
catch (SQLException e)
{
//throw new UnavailableException("error: " + e);
}
catch (Exception e)
{
//throw new UnavailableException("error: " +e);
}
//make a callable statement for a stored procedure.
//It has four parameters
try
{
System.out.println("sending datacall");
CallableStatement cstmt = dbConn.prepareCall(
"{call storePageValues(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?)}");
//set the values of the stored procedure's input
parameters
//out.println("calling stored procedure . . .");
cstmt.setString(1, Username);
cstmt.setString(2, pass);
cstmt.setString(3, aboutus);
cstmt.setString(4, aboutustitle);
cstmt.setString(5, services);
cstmt.setString(6, servicestitle);
cstmt.setString(7, contactus);
cstmt.setString(8, contactustitle);
cstmt.setString(9, misc);
cstmt.setString(10, misctitle);
cstmt.setString(11, main);
cstmt.setString(12, maintitle);
//cstmt.setString(5, notes);
//now that the input parameters are set, we can proceed to
execute the insertTheForm stored procedure
cstmt.execute();
returnValue=true;
//out.println("stored procedure executed");
//out.close();
}
catch (SQLException e)
{
//throw new UnavailableException("error: " + e);
}
return returnValue;
}
}
Comment from dprasad
Date: 10/19/2003 11:24PM PDT Your Comment
NOTE: THE SHOWPAGE.JSP FILENAME IS MISLEADING, SORRY FOR THE CONFUSION
IT IS ACTUALLY FOR PUTTING VALUES IN THE DATABASE
- Next message: Paul Lutus: "Re: how to get the path of my current class that running?"
- Previous message: Sudsy: "Re: Hashtable and Synchronization"
- Next in thread: Jon Martin Solaas: "Re: Prblems accessing a bean from JSP"
- Reply: Jon Martin Solaas: "Re: Prblems accessing a bean from JSP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|