随笔-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的驱动包

(2)hibernate.cfg.xml的同时最好把”Create a console configuration”复选项加上,如果没有,后来要建”console configuration”则要在hibernate视图下建。 
 

4 功能规划

 (1table

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

  2)英语单词表english_word  id,name,content,userid,book,class,forExampletime

  3)课文表 id,content,expression(语法),exercise(习题),time

  4)其它(other)看到的句子,单词,语法 ,歌词,电影对白等等

    id,content,time

  5java专用词  id,name,content,time


5 功能
   

功能 难度 时间 优先级 一期 二期 三期
基本功能 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 阅读(318) 评论(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 及对应的静态页

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> 出现在页面上,问题出在:
虽然 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 。  
  在"word" 表对应的 java 文件中,加入:
@GeneratedValue(strategy = GenerationType.SEQUENCE)


-------------下面是结果


@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 页的动态截选(最后做)  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: