Win a copy of Terraform in Action this week in the Cloud forum!

tuntun zaw

Greenhorn
+ Follow
since Oct 23, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tuntun zaw

connector j is used with jdbc.
connector/ODBC can be used with jdbc?
Data centric jsf application

what book i should read for data centric jsf application?

I have some problem with my jsf application using database connection.
I use jsf, managed bean and database bean.I use normal plain java.
The problem is occured during linking between managed bean and database bean.

Error is variable result might not be initialized.
If any error do not occcur, result is not generated.
The method in managed bean cannot generate result.

why?please give me some example.What book i should read.

I want to use jsf, jdbc and normal plain java.That is possible?
What effects can cause?
I have no experience in other database component such as entity bean.

My web service directory is apache tomcat.I use odbcjdbc driver and ms access database.

Here is my code.

DatabaseBean.java

package mainclasses;

import java.io.*;
import java.sql.*;

public class DatabaseBean {

private static final String jdbcDriverClass =
"sun.jdbc.odbc.JdbcOdbcDriver";
private static final String jdbcDatabaseURL =
"jdbc:odbc:Employees";
private Connection conn;

public DatabaseBean() throws Exception {
try {
// Load the JDBC-ODBC driver.
Class.forName(jdbcDriverClass);
// Open a database connection.
connect();
} catch(SQLException ex) {
// Perform any cleanup.
cleanup();
// Rethrow exception.
throw(ex);
}
}

public void connect() throws SQLException {
if(conn != null) {
cleanup();
conn = null;
}
// Open a database connection.
conn = DriverManager.getConnection(jdbcDatabaseURL);
}

public void cleanup() throws SQLException {
// Close the Connection.
if(conn != null) {
conn.close();
}
}

// The onus is on the user to close the Statement that created
// the returned ResultSet.
public ResultSet query(String queryStatement)
throws SQLException {
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();

rs = stmt.executeQuery(queryStatement);
} catch(SQLException ex) {

try {
if(stmt != null) {
stmt.close();
}
} catch(SQLException ex2) {
}
finally {
throw(ex);
}
}
return(rs);
}

public int insert(String insertStatement) throws SQLException {
return(update(insertStatement));
}

public int delete(String deleteStatement) throws SQLException {
return(update(deleteStatement));
}

public int update(String updateStatement) throws SQLException {
Statement stmt = null;
int numRows = -1;
try {
stmt = conn.createStatement();
numRows = stmt.executeUpdate(updateStatement);
} catch(SQLException ex) {
try {
if(stmt != null) {
stmt.close();
}
} catch(SQLException ex2) {
} finally {
throw(ex);
}
} finally {
try {
if(stmt != null) {
stmt.close();
}
} catch(SQLException ex) {
}
}
return(numRows);
}


public Connection getConnection() {
return(conn);
}
}


simplelogin.java

package mainclasses;

import java.sql.*;
import java.io.*;
import mainclasses.*;

public class SimpleLogin{
String loginname;
String password;
String result;
DatabaseBean db;

public SimpleLogin(){}

public String getLoginname(){
return loginname;
}

public void setLoginname(String loginname){
this.loginname = loginname;
}

public String getResult(){
return result;
}


public String getPassword(){
return password;
}

public void setPassword(String password){
this.password = password;
}

public String CheckValidUser(){
String query="SELECT username,password FROM login ";

try{

ResultSet rs=db.query(query);


while(rs.next()){
result=null;

if(loginname.equals(rs.getString("username"))&&password.equals(rs.getString("password")))
{
result="success";
rs.afterLast();
}
else
result="fail";
}
}catch(SQLException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}

return result;

}
}
13 years ago
JSF
Address inverse
My welcome file is welcome.faces redirected by index.html. When browser load welcome.faces, address bar show like �http://localhost/logo/welcome.faces�.When click the command buttom after filling text box, browser load success.faces. But address bar show �http://localhost/logo/welcome.faces�. When click command buttom in success.faces, browser load welcome.faces. But address bar show �http://localhost/logo/success.faces�. At this time, when click the command buttom in welcome.faces without no change in text box, address bar change from �http://localhost/logo/success.faces� to �http://localhost/logo/welcome.faces�.But form have no change.What is wrong?
My web service directory is apache tomcat.

Give me correct flow and why?
My email address is tunzaw2008@gmail.com.

Here is my code.
web.xml.
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

welcome.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head>
<title>Hello Welcome</title>
</head>
<body>
<f:view>
<h:form id="inputname">

<p>
<h:outputText value="Enter name:"/>
</p>


<h:inputText value="#{namebean.username}" required="true">

</h:inputText>

<h:commandButton value="Submit" action="success"/>


</h:form>
</f:view>
</body>
</html>

success.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head>
<title>Successful</title>
</head>
<body>
<f:view>
<h:form id="Successful">

<p>
<h:outputText value="Hi "/>
<h:outputText value="#{namebean.username}"/>
</p>

<h:commandButton value="Submit" action="welcome"/>
</h:form>
</f:view>
</body>
</html>
namebean.java

package jsfclasses;

public class namebean{
private String username;
private String r;

public void setUsername(String name){
this.username=name;
}

public String getUsername(){
return username;
}

}

faces-config.xml

<navigation-rule>
<from-view-id>/welcome.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/success.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/success.jsp</from-view-id>
<navigation-case>
<from-outcome>welcome</from-outcome>
<to-view-id>/welcome.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<managed-bean>
<managed-bean-name>namebean</managed-bean-name>
<managed-bean-class>jsfclasses.namebean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>

</managed-bean>
13 years ago
JSF
My welcome file is welcome.faces.When browser load welcome.faces,address bar show like
"http://localhost/tuntun/welcome.faces".When click the search buttom after filling text fields,following errors occur.

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: javax.servlet.ServletException: javax.servlet.jsp.JspException:
javax.faces.el.PropertyNotFoundException: Error getting property 'tripType' from bean of type jsfclasses.flightsearch

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)


My web service directory is apache tomcat.

welcome.faces

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
<head>
<title>Freedom Airlines Online Flight Reservation System</title>
</head>
<body>
<h:form>
<h2>Search Flights</h2>
<table>
<tr><td colspan="4">Where and when do you want to travel?</td></tr>
<tr>
<td colspan="2">Leaving from:</td>
<td colspan="2">Going to:</td>
</tr>
<tr>
<td colspan="2">
<h:inputText value="#{flight.origination}" size="35"/>
</td>
<td colspan="2">
<h:inputText value="#{flight.destination}" size="35"/>
</td>
</tr>
<tr>
<td colspan="2">Departing:</td>
<td colspan="2">Returning:</td>
</tr>
<tr>
<td>
<h:inputText value="#{flight.departDate}"/>
</td>

<td>
<h:inputText value="#{flight.departTime}"/>
</td>
<td>
<h:inputText value="#{flight.returnDate}"/>
</td>
<td>
<h:inputText value="#{flight.returnTime}"/>
</td>
</tr>
</table>
<p>
<h:commandButton value="Search" action="submit"/>
</p>
</h:form>
</body>
</f:view>
</html>

searchresult.faces

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<head>
<title>Freedom Airlines Online Flight Reservation System</title>
</head>
<body>
<h3>You entered these search parameters</h3>
<p>Origination: <h:outputText value="#{flight.origination}"/>
<p>Depart date: <h:outputText value="#{flight.departDate}"/>
<p>Depart time: <h:outputText value="#{flight.departTime}"/>
<p>Destination: <h:outputText value="#{flight.destination}"/>
<p>Return date: <h:outputText value="#{flight.returnDate}"/>
<p>Return time: <h:outputText value="#{flight.returnTime}"/>
<p>Trip type : <h:outputText value="#{flight.tripType}"/>
</body>
</f:view>
</html>

web.xml

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

faces-config.xml

<navigation-rule>
<from-view-id>/welcome.jsp</from-view-id>
<navigation-case>
<from-outcome>submit</from-outcome>
<to-view-id>/searchresult.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<managed-bean>
<managed-bean-name>flight</managed-bean-name>
<managed-bean-class>jsfclasses.flightsearch</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>

<managed-property>
<property-name>origination</property-name>
<null-value/>
</managed-property>

<managed-property>
<property-name>destination</property-name>
<null-value/>
</managed-property>

<managed-property>
<property-name>departDate</property-name>
<null-value/>
</managed-property>

<managed-property>
<property-name>departTime</property-name>
<null-value/>
</managed-property>

<managed-property>
<property-name>returnDate</property-name>
<null-value/>
</managed-property>

<managed-property>
<property-name>returnTime</property-name>
<null-value/>
</managed-property>
</managed-bean>
13 years ago
JSF