隨筆-42  評(píng)論-42  文章-0  trackbacks-0

            1 web.xml 文件的配置

            在引入Spring 后,想要建一個(gè)beans.xml作為Spring的配置文件,而不是默認(rèn)的 english-servlet.xml

          web.xml:

          ……

          <servlet>

           <servlet-name>english</servlet-name>

           <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class>

           <init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>/WEB-INF/beans.xml</param-value>

           </init-param>

           <load-on-startup>1</load-on-startup>

          </servlet>

           

          2 引入tiles時(shí)配置文件的改動(dòng):

          Beans.xml:

            在beans.xml里加入以下<bean>

          <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">

          <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />

          </bean>

          <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">

          <property name="definitions">

          <list>

          <value>/WEB-INF/tiles.xml</value>

          </list>

          </property>

          </bean>

          <bean name="/*.view" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"></bean>

          web.xml加入:

          <servlet-mapping>

          <servlet-name>english</servlet-name>

          <url-pattern>*.view</url-pattern>

          </servlet-mapping>

          tiles.xml文件,并試運(yùn)行

          Tiles.xml:

          <?xml version="1.0" encoding="UTF-8"?>

          <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"

          "http://tiles.apache.org/dtds/tiles-config_2_0.dtd" >

          <tiles-definitions>

            <definition name=""/>

            <definition name="index" template="/index.jsp"></definition>

          </tiles-definitions>

          運(yùn)行 ,url=“http://localhost:8080/english/index.view”

           

          3 引入hibernate

          (1)除了要有hibernatehibernate_annotation的自身包和lib包外,還要有jdbc的驅(qū)動(dòng)包

          (2)hibernate.cfg.xml的同時(shí)最好把”Create a console configuration”復(fù)選項(xiàng)加上,如果沒(méi)有,后來(lái)要建”console configuration”則要在hibernate視圖下建。 
           

          4 功能規(guī)劃

           (1table

            1)用戶(hù)表english_user id, password, 格言,

            2)英語(yǔ)單詞表english_word  id,name,content,userid,book,class,forExampletime

            3)課文表 id,content,expression(語(yǔ)法),exercise(習(xí)題),time

            4)其它(other)看到的句子,單詞,語(yǔ)法 ,歌詞,電影對(duì)白等等

              id,content,time

            5java專(zhuān)用詞  id,name,content,time


          5 功能
             

          功能 難度 時(shí)間 優(yōu)先級(jí) 一期 二期 三期
          基本功能 1 1 1    
          背單詞(包括定時(shí)提醒)
          2 2 6    
          導(dǎo)入導(dǎo)出到文件 2 2 4    
          專(zhuān)輯單詞表 1 1 2    
          錄放功能 3 3      
          好友(包括引用) 1 1 3    
          用戶(hù)積分、聲望(提問(wèn)、回答) 2 1       ☆ 
          共享(共同翻譯) 1 1 5    

          暫定一期為期7天

          posted on 2008-06-03 02:35 BlueSunshine 閱讀(346) 評(píng)論(7)  編輯  收藏 所屬分類(lèi): 學(xué)習(xí)心得

          評(píng)論:
          # re: 建 English 項(xiàng)目遇到的問(wèn)題 2008-06-03 15:28 | 哈哈的日子
          support
          寫(xiě)得不錯(cuò),通俗易懂,以后俺就向你學(xué)習(xí)了。  回復(fù)  更多評(píng)論
            
          # re: 建 English 項(xiàng)目遇到的問(wèn)題 2008-06-04 10:24 | BlueSunshine
          6 Spring 與 Hibernate 的集成

          在 beans.xml 加入: 
          <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
                  
          <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
                  
          <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
                  
          <property name="username" value="yiqi" />
                  
          <property name="password" value="haha" />
              
          </bean>
              
              
          <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                  
          <property name="dataSource" ref="myDataSource"></property>
                  
          <property name="hibernateProperties">
                      
          <props>
                          
          <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                          
          <prop key="hbm2ddl.auto">create</prop>
                          
          <prop key="current_session_context_class">thread</prop>
                      
          </props>
                  
          </property>
                  
          <property name="annotatedClasses">
                      
          <list>
                          
          <value>com.english.user.EnglishUser</value>
                          
          <value>com.english.word.EnglishWord</value>
                      
          </list>
                  
          </property>
              
          </bean>
              
          <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                  
          <property name="dataSource" ref="myDataSource"></property>
                  
          <property name="sessionFactory" ref="sessionFactory"></property>
              
          </bean>
              
          <tx:annotation-driven/>
              
          <context:component-scan base-package="com.english.controller"></context:component-scan>


            回復(fù)  更多評(píng)論
            
          # re: 建 English 項(xiàng)目遇到的問(wèn)題 2008-06-10 09:24 | BlueSunshine
          7 完成了UserController, UserDAO, UserService 及對(duì)應(yīng)的靜態(tài)頁(yè)

          EnglishUserController:
          package com.english.controller;

          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpSession;

          import org.springframework.beans.factory.annotation.Autowired;
          import org.springframework.stereotype.Controller;
          import org.springframework.web.bind.annotation.RequestMapping;

          import com.english.user.EnglishUser;
          import com.english.user.EnglishUserService;
          import com.english.user.LoginException;

          @Controller
          public class EnglishUserController {
              
          //自動(dòng)寫(xiě)入
              @Autowired
              
          private EnglishUserService englishUserService;

              @RequestMapping(
          "/register.do")
              
          public String addEnglishUser(HttpServletRequest req, EnglishUser englishUser) {
                  englishUserService.addEnglishUser(englishUser);
                  req.getSession().setAttribute(
          "englishUser", englishUser);
                  
          return "index";

              }


              @RequestMapping(
          "/login.do")
              
          public String loginEnglishUser(HttpSession session, EnglishUser englishUser) {
                  
          try {
                      EnglishUser englishUserTest 
          = englishUserService.vefifyEnglishUser(englishUser);
                      session.setAttribute(
          "englishUser", englishUserTest);
                      
          return "index";
                  }
           catch (LoginException e) {
                      
          return "loginFail";
                  }

              }


              @RequestMapping(
          "/logout.do")
              
          public String logout(HttpSession session) {
                  
          //session.removeAttribute("englishUser");之前寫(xiě)的是這句,下面的是自己新想出來(lái)的
                  session.setAttribute("englishUser"null);
                  
          return "index";
              }


              
          public EnglishUserService getEnglishUserService() {
                  
          return englishUserService;
              }


              
          public void setEnglishUserService(EnglishUserService englishUserService) {
                  
          this.englishUserService = englishUserService;
              }

          }


          錯(cuò)誤之一,沒(méi)在
          "private EnglishUserService englishUserService"前面加標(biāo)注:
           @autowired   回復(fù)  更多評(píng)論
            
          # re: 建 English 項(xiàng)目遇到的問(wèn)題 2008-06-10 10:23 | BlueSunshine
          8 “登錄失敗”的問(wèn)題

          topLogin.jsp:(template 里的 "top" 部分)
          <%@page import="com.english.user.EnglishUser;"%>
          <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

          <%
              EnglishUser englishUser 
          = (EnglishUser) session.getAttribute("englishUser");
              
          String englishUserId = "游客";
              
          if (englishUser != null)
                  englishUserId 
          = englishUser.getUserid();
          %>
          <table background="img/beijing_flower.jpg" width="1024" height="228">
              
          <tr>
                  
          <td>Welcome to 'Sunshine zone'!登錄身份:<%=englishUserId%></td>
              
          </tr>
              
          <c:if test="${sessionScope.englishUser!=null}">
                  
          <tr>
                      
          <td><href="logout.do">logout</a></td>
                  
          </tr>
              
          </c:if>
          </table>

          在“登錄失敗”后 "logout" 對(duì)應(yīng)的 <td> 出現(xiàn)在頁(yè)面上,問(wèn)題出在:
          雖然 session 為 null ,但是 request 里面有 englishUser ,所以在同名的情況出錯(cuò)。(為框架沖突)
          解決方法:
          <c:if test="${sessionScope.englishUser!=null}">
          給出范圍,只找session 類(lèi)型的 englishUser   回復(fù)  更多評(píng)論
            
          # re: 建 English 項(xiàng)目遇到的問(wèn)題 2008-06-10 14:32 | BlueSunshine
          10 兩表關(guān)連
            第一次用兩到表的關(guān)連,在"word"表里有"userId"這一列,而這列來(lái)自表"user"。用 Hibernate 生成的兩個(gè)表對(duì)應(yīng)文件和之前的不同,可能在取值的時(shí)候方便一些,還沒(méi)用到,只是想法。

            期待中......  回復(fù)  更多評(píng)論
            
          # re: 建 English 項(xiàng)目遇到的問(wèn)題 2008-06-10 14:57 | BlueSunshine
          11 表"word"引入 sequence   
            表"word" 的"wordId" 列是自動(dòng)生成的,要用 sequence 。  
            在"word" 表對(duì)應(yīng)的 java 文件中,加入:
          @GeneratedValue(strategy = GenerationType.SEQUENCE)


          -------------下面是結(jié)果


          @Id
              @Column(name 
          = "WORD_ID", nullable = false, precision = 10, scale = 0)
              @GeneratedValue(strategy 
          = GenerationType.SEQUENCE)
              
          public int getWordId() {
                  
          return this.wordId;
              }
          這樣就可以了   回復(fù)  更多評(píng)論
            
          # re: 建 English 項(xiàng)目遇到的問(wèn)題 2008-06-26 22:36 | BlueSunshine
          基本功能補(bǔ)充:

          1 單詞表的分頁(yè);
          2 insert / update 后的定位;
          3 index 頁(yè)的動(dòng)態(tài)截選(最后做)  回復(fù)  更多評(píng)論
            
          主站蜘蛛池模板: 平山县| 永寿县| 花莲县| 平原县| 阿合奇县| 新乐市| 尚义县| 安乡县| 高台县| 项城市| 鹤岗市| 武邑县| 通化市| 佳木斯市| 宜城市| 襄樊市| 江门市| 临西县| 尚义县| 曲沃县| 平潭县| 绥滨县| 凤山市| 临桂县| 广宁县| 衡南县| 乌什县| 株洲市| 东乡族自治县| 秭归县| 工布江达县| 彩票| 保山市| 太仓市| 惠东县| 琼结县| 扶余县| 鄄城县| 广汉市| 静海县| 迁西县|