您的位置:程序门 -> java -> web 开发



[jsf]谁有jsf实现添加 删除 修改 的程序!!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


[jsf]谁有jsf实现添加 删除 修改 的程序!![已结贴,结贴人:lzyboy]
发表于:2007-07-14 11:57:22 楼主
谁有jsf实现添加   删除   修改   的程序!!    

给我一份   lzyboy521@163.com

谢谢~~~
发表于:2007-07-14 12:35:101楼 得分:0
怎么没有人回答啊?

我在线等的!
发表于:2007-07-14 12:41:242楼 得分:40
哪本jsf的书上增删改查都应该是基础的例子吧?
发表于:2007-07-14 12:45:543楼 得分:0
<%@page   contenttype= "text/html;   charset=gbk "%>
<%@taglib   uri= "http://java.sun.com/jsf/core "   prefix= "f "%>
<%@taglib   uri= "http://java.sun.com/jsf/html "   prefix= "h "%>
<html>
<head>
<title> reg </title>
</head>
<body   bgcolor= "#ffffff ">
<h1> 注册 </h1>
<f:view>
    <h:form   id= "regform ">
        <h:outputlabel   value= "姓名 "   for= "name ">         </h:outputlabel>
        <h:inputtext   id= "name "   value= "#{userbean.name} "   required= "true ">         </h:inputtext>
        <h:message   for= "name ">         </h:message>
        <p>         </p>
        <h:outputlabel   value= "年龄 "   for= "age ">         </h:outputlabel>
        <h:inputtext   id= "age "   value= "#{userbean.age} "   required= "true ">         </h:inputtext>
        <h:message   for= "age ">         </h:message>
        <p> </p>
        <h:commandbutton   id= "submit "   action= "#{userbean.add} "   value= "提交 ">         </h:commandbutton>
    </h:form>
</f:view>
</body>
</html>


========================================

package   jsforacle;


import   java.util.arraylist;
import   java.sql.connection;
import   java.sql.drivermanager;
import   java.sql.sqlexception;
import   java.sql.resultset;
import   java.sql.statement;
import   java.sql.preparedstatement;

public   class   userbean   {
        private   string   name;
        private   int   age;
        private   int   id;

        private   connection   getcon(){
                connection   con   =   null;
                string   user   =   "magus ";
                string   password   =   "magus ";
                try   {
                        class.forname( "oracle.jdbc.driver.oracledriver ").newinstance();
                        con   =   drivermanager.getconnection( "jdbc:oracle:thin:@127.0.0.1:1521:magus ",   user,   password);
                }   catch   (classnotfoundexception   ex)   {
                        system.out.println(ex);
                }   catch   (illegalaccessexception   ex)   {
                        system.out.println(ex);
                }   catch   (instantiationexception   ex)   {
                        system.out.println(ex);
                }   catch   (sqlexception   e)   {
                        system.out.println(e);
                }
                return   con;
        }

        private   int   getmaxid(){
                int   maxid   =   1;
                connection   con   =   getcon();
                resultset   rs   =   null;
                statement   stmt   =   null;
                string   sql   =   "select   max(id)   as   maxid   from   users ";
                try   {
                        stmt   =   con.createstatement();
                        rs   =   stmt.EXECutequery(sql);
                        if(rs.next()){
                                maxid   =   rs.getint( "maxid ");
                        }
                }   catch   (sqlexception   ex)   {
                        system.out.println(ex);
                }finally{
                        try   {
                                con.close();
                        }   catch   (sqlexception   ex1)   {
                                system.out.println(ex1);
                        }
                }
                return   maxid;
        }

        public   string   add()   {
                connection   con   =   getcon();
                try   {
                        preparedstatement   pstmt   =   con.preparestatement(
                                        "insert   into   users   values   (?,?,?) ");
                        pstmt.setstring(1,name);
                        pstmt.setint(2,age);
                        pstmt.setint(3,getmaxid()+1);
                        pstmt.EXECuteupdate();
                        return   "success ";
                }   catch   (sqlexception   ex)   {
                        system.out.println(ex);
                        return   "fales ";
                }   finally   {
                        try   {
                                con.close();
                        }   catch   (sqlexception   ex1)   {
                                system.out.println(ex1);
                        }
                }
        }

        public   userbean()   {
        }

        public   void   setname(string   name)   {
                this.name   =   name;
        }

        public   void   setage(int   age)   {
                this.age   =   age;
        }

        public   void   setid(int   id)   {
                this.id   =   id;
        }

        public   string   getname()   {
                return   name;
        }

        public   int   getage()   {
                return   age;
        }

        public   int   getid()   {
                return   id;
        }
}

==========================================

<?xml   version= "1.0 "   encoding= "utf-8 "?>
<!doctype   faces-config   public   "-//sun   microsystems,   inc.//dtd   javaserver   faces   config   1.1//en "   "http://java.sun.com/dtd/web-facesconfig_1_1.dtd ">

<faces-config   xmlns= "http://java.sun.com/jsf/configuration ">
    <managed-bean>
        <managed-bean-name> userbean </managed-bean-name>
        <managed-bean-class> jsforacle.userbean </managed-bean-class>
        <managed-bean-scope> session </managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id> /reg.jsp </from-view-id>
        <navigation-case>
            <from-outcome> success </from-outcome>
            <to-view-id> /result.jsp </to-view-id>
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <from-view-id> /reg.jsp </from-view-id>
        <navigation-case>
            <from-outcome> false </from-outcome>
            <to-view-id> /result2.jsp </to-view-id>
        </navigation-case>
    </navigation-rule>
</faces-config>

===========================================

<?xml   version= "1.0 "   encoding= "utf-8 "?>
<web-app   xmlns= "http://java.sun.com/xml/ns/j2ee "   xmlns:xsi= "http://www.w3.org/2001/xmlschema-instance "   xsi:schemalocation= "http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "   version= "2.4 ">
    <display-name> webmodule1 </display-name>
    <servlet>
        <servlet-name> faces   servlet </servlet-name>
        <servlet-class> javax.faces.webapp.facesservlet </servlet-class>
        <load-on-startup> 1 </load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name> faces   servlet </servlet-name>
        <url-pattern> *.faces </url-pattern>
    </servlet-mapping>
</web-app>

发表于:2007-07-14 21:45:464楼 得分:0
有没有完整点的     就是3个功能全有的   我刚刚学     还没有买书~~
发表于:2007-07-15 10:42:085楼 得分:0
实现其他的功能无非就是在受管理bean里再添加   del   ,   update,   select   的方法,都是   jdbc   基础,搂主不会这么懒吧?
发表于:2007-07-15 21:44:356楼 得分:0
呵呵

我才不懒呢     自己去写代码了~~    

给分了


快速检索

最新资讯
热门点击