3月28日,天气晴天,太阳大的很呢…
今天在用Spring+WebWork+Hibernate测试学习,遇到了些问题,下面来总结一下
1.WebWork解决中文字符乱码问题
在WebWork..properties文件里加入一段代码即可.
webwork.i18n.encoding = gb2312
2.在Spring配置文件ApplicationContent.xml中导入其他配置文件方法如下:
<!-- 导入DAO配置文件 -->
<import resource="daoContext.xml"/>
<!-- 导入SERVICE配置文件 -->
<import resource="serviceContext.xml"/>
<!-- 导入ACTION配置文件 -->
<import resource="actionContext.xml"/>
3.在用Hibernate的时候,遇到了表民是关键字的部分
结果在网上查了一下,找到了解决方法
就是在Hibernate的配置文件 如User.hbm.xml 里,在表名加上”`User`”也就是数字键”1”左边,”TAB”键上面的这个键,就能解决冲突问题了,同样字段也可以用这个方法
<?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>
4.WebWork 操作Session,Request,Response
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);
5.JSTL判断NULL值
<c:if test=”${empty USER}”>
<c:out value=”空值”/>
</c:if>
这些就是今天遇到的问题...