3月28日 工作日記

3月28日,天氣晴天,太陽大的很呢…
今天在用Spring+WebWork+Hibernate測試學習,遇到了些問題,下面來總結一下
1.WebWork解決中文字符亂碼問題
在WebWork..properties文件里加入一段代碼即可.
[code]webwork.i18n.encoding = gb2312[/code]
2.在Spring配置文件ApplicationContent.xml中導入其他配置文件方法如下:
[code]
<!-- 導入DAO配置文件 -->
<import resource="daoContext.xml"/>
<!-- 導入SERVICE配置文件 -->
<import resource="serviceContext.xml"/>
<!-- 導入ACTION配置文件 -->
<import resource="actionContext.xml"/>
[/code]
3.在用Hibernate的時候,遇到了表民是關鍵字的部分
結果在網上查了一下,找到了解決方法
就是在Hibernate的配置文件 如User.hbm.xml 裏,在表名加上”`User`”也就是數字鍵”1”左邊,”TAB”鍵上面的這個鍵,就能解決衝突問題了,同樣字段也可以用這個方法
[code]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.esc.data.vo.User" table="`user`">
<id name="UId" type="java.lang.Integer">
<column name="u_id" />
<generator class="identity" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="20" not-null="true" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="50" not-null="true" />
</property>
<property name="truename" type="java.lang.String">
<column name="truename" length="20" />
</property>
<property name="qq" type="java.lang.String">
<column name="qq" length="10" />
</property>
<property name="msn" type="java.lang.String">
<column name="msn" length="100" />
</property>
<property name="email" type="java.lang.String">
<column name="email" length="100" />
</property>
<property name="mobile" type="java.lang.String">
<column name="mobile" length="11" />
</property>
<property name="address" type="java.lang.String">
<column name="address" length="200" />
</property>
<set name="reviews" inverse="true">
<key>
<column name="u_id" />
</key>
<one-to-many class="com.esc.data.vo.Review" />
</set>
<set name="infos" inverse="true">
<key>
<column name="u_id" />
</key>
<one-to-many class="com.esc.data.vo.Info" />
</set>
<set name="messages" inverse="true">
<key>
<column name="u_id" />
</key>
<one-to-many class="com.esc.data.vo.Message" />
</set>
</class>
</hibernate-mapping>
[/code]
4.WebWork 操作Session,Request,Response
[code]
import com.opensymphony.xwork.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionContext;
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);
Map session = (Map) ActionContext.getContext().get("session");
session.put("USER",user);
[/code]
5.JSTL判斷NULL值
[code]
<c:if test=”${empty USER}”>
<c:out value=”空值”/>
</c:if>
[/code]
這些就是今天遇到的問題...
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章