隨筆-42  評論-42  文章-0  trackbacks-0

            1 web.xml 文件的配置

            在引入Spring 后,想要建一個beans.xml作為Spring的配置文件,而不是默認的 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時配置文件的改動:

          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文件,并試運行

          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>

          運行 ,url=“http://localhost:8080/english/index.view”

           

          3 引入hibernate

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

          (2)hibernate.cfg.xml的同時最好把”Create a console configuration”復選項加上,如果沒有,后來要建”console configuration”則要在hibernate視圖下建。 
           

          4 功能規(guī)劃

          ?。?/span>1table

            1)用戶表english_user id, password, 格言,

            2)英語單詞表english_word  id,name,content,userid,book,class,forExample,time

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

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

              id,content,time

            5java專用詞  id,name,content,time


          5 功能
             

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

          暫定一期為期7天

          posted on 2008-06-03 02:35 BlueSunshine 閱讀(346) 評論(7)  編輯  收藏 所屬分類: 學習心得

          評論:
          # re: 建 English 項目遇到的問題 2008-06-03 15:28 | 哈哈的日子
          support
          寫得不錯,通俗易懂,以后俺就向你學習了。  回復  更多評論
            
          # re: 建 English 項目遇到的問題 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>


            回復  更多評論
            
          # re: 建 English 項目遇到的問題 2008-06-10 09:24 | BlueSunshine
          7 完成了UserController, UserDAO, UserService 及對應的靜態(tài)頁

          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 {
              
          //自動寫入
              @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");之前寫的是這句,下面的是自己新想出來的
                  session.setAttribute("englishUser"null);
                  
          return "index";
              }


              
          public EnglishUserService getEnglishUserService() {
                  
          return englishUserService;
              }


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

          }


          錯誤之一,沒在
          "private EnglishUserService englishUserService"前面加標注:
           @autowired   回復  更多評論
            
          # re: 建 English 項目遇到的問題 2008-06-10 10:23 | BlueSunshine
          8 “登錄失敗”的問題

          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" 對應的 <td> 出現(xiàn)在頁面上,問題出在:
          雖然 session 為 null ,但是 request 里面有 englishUser ,所以在同名的情況出錯。(為框架沖突)
          解決方法:
          <c:if test="${sessionScope.englishUser!=null}">
          給出范圍,只找session 類型的 englishUser   回復  更多評論
            
          # re: 建 English 項目遇到的問題 2008-06-10 14:32 | BlueSunshine
          10 兩表關連
            第一次用兩到表的關連,在"word"表里有"userId"這一列,而這列來自表"user"。用 Hibernate 生成的兩個表對應文件和之前的不同,可能在取值的時候方便一些,還沒用到,只是想法。

            期待中......  回復  更多評論
            
          # re: 建 English 項目遇到的問題 2008-06-10 14:57 | BlueSunshine
          11 表"word"引入 sequence   
            表"word" 的"wordId" 列是自動生成的,要用 sequence ?! ?br />   在"word" 表對應的 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;
              }
          這樣就可以了   回復  更多評論
            
          # re: 建 English 項目遇到的問題 2008-06-26 22:36 | BlueSunshine
          基本功能補充:

          1 單詞表的分頁;
          2 insert / update 后的定位;
          3 index 頁的動態(tài)截選(最后做)  回復  更多評論
            
          主站蜘蛛池模板: 陆良县| 封开县| 高青县| 灌南县| 乌拉特前旗| 汝州市| 房山区| 南安市| 水富县| 申扎县| 双鸭山市| 广河县| 乃东县| 石景山区| 石狮市| 奉节县| 南开区| 苏尼特右旗| 峡江县| 碌曲县| 巫溪县| 隆回县| 邵阳县| 云霄县| 阜平县| 腾冲县| 石狮市| 花莲县| 重庆市| 安吉县| 长兴县| 依兰县| 酉阳| 定州市| 会理县| 常宁市| 巴彦淖尔市| 明溪县| 余庆县| 怀来县| 龙口市|