JavaEE学习笔记

设置Session

ActionContext.getContext().getSession().put("user",getUsername());

获得Session

String user=(String) ActionContext.getContext().getSession().get("user");

如何在jsp输出Hibernate查询到的内容

list如果是封装在src内 可以用getter和setter然后转向到前台JSP

在前台

<s:iterator value="list">
<tr>
   <td>
          ${id}
  </td>
<td >
         ${name}
</td>
<td>
         ${yuan}
</td>
<td>
         ${money}
</td>
<td>
        <!--  -->
</td>
</tr>
</s:iterator>

即可

Structs 2 Action乱码问题解决,在structs.xml中设置

<constant name="struts.i18n.encoding" value="GB2312" />

Hibernate MySql乱码问题解决,在Hibernate.cfg.xml中设置

<property name="hibernate.connection.url">
        jdbc:mysql:///hair?useUnicode=true&amp;characterEncoding=UTF-8
    </property>

即可

Structs 2链接参数(list中的值)

 <s:url id="buy" action="Buy">
              <s:param name="id">${id}</s:param>
       </s:url>
       <s:a href="%{buy}">扣费</s:a>

为了实现文件上传,需要把form的属性添加为下:

<form method="post" action="addNotice" enctype="multipart/form-data">

不然会报错

Invalid field value for field xxx
原文地址:https://www.cnblogs.com/bq12345/p/3096955.html