当前位置:编程学习 > JAVA >>

struts 2求教,登录用户新建一个计划,怎么把当前登录的用户的id直接赋值给计划表中一个字段。

<s:hidden name="bean.planget"/>
<table class="tableStyle" width="60%" align="center" cellpadding="0px" cellspacing="0px"
style="margin-left:auto;margin-right:auto">
    <tr>
     <th align="right"><b>计划名称<span class="red">*</span></b></th>     
        <td align="left">
         <s:textfield name="bean.planInfoName" id="planInfoName" maxlength="20" />
         <span id="planInfoNameNull" class="red"> </span>
         </td>
    </tr>
<tr>
     <th width="18%" align="right"><b>计划条数<span class="red">*</span></b></th>       
        <td align="left">
         <s:textfield name="bean.planInfoNum" id="planInfoNum" maxlength="20" />
         <span id="planInfoNumNull" class="red"> </span>
      </td>
    </tr>
     <tr>
     <th align="right"><b>计划时间<span class="red">*</span></b></th>
        <td align="left">
         <s:textfield name="bean.planInfoTime" id="planInfoTime" maxlength="20"  onClick="WdatePicker()" class="Wdate" />
                          <span id="planInfoTimeNull" class="red"> </span>
        </td>
     </tr>
     <tr>
     <th align="right"><b>承办领导</b></th>
        <td>        
         <s:textfield name="bean.planInfoMyPL" id="planInfoMyPL" maxlength="20" />
        </td>
     </tr>
     <tr>
     <th align="right"><b>责任单位承办人<span class="red">*</span></b></th>
        <td align="left">
         <s:textfield name="bean.planInfoPeople" id="planInfoPeople" maxlength="20" />
        </td>
     </tr>
     <tr>
     <th align="right"><b>完成时间<span class="red">*</span></b></th>
        <td align="left">
         <s:textfield name="bean.planInfoOKTime" id="planInfoOKTime" maxlength="20"  onClick="WdatePicker()" class="Wdate"/>
                  <span id="planInfoOKTimeNull" class="red"> </span>
        
        </td>
     </tr>
     <tr>
     <th align="right"><b>建议</b></th>
        <td align="left">
         <s:textarea name="bean.idea"/>
                  <span id="ideaNull" class="red"> </span>
        </td>
     </tr>  
     <tr>
     <th align="right"><b>计划内容<span class="red">*</span></b></th>
        <td align="left">
         <s:textarea name="bean.planInfoDetail" id="planInfoDetail"/>
                  <span id="planInfoDetailNull" class="red"> </span>
        </td>
     </tr>  
     <tr>
     <th align="right"><b>备注</b></th>
        <td align="left">
         <s:textarea name="bean.remark"/>
        </td>
        
     </tr>  
      <tr>
       [color=#FF0000] <th align="right"><b>计划撰写人</b></th>
        <td align="left">
            <s:textarea name="bean.planset" value="#session.user.getRealName()"/>
           </td>
           </tr>[/color]
        
        <tr>
        <th align="right"><b>计划部门</b></th>
        <td align="left">
            <s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/>
        </td>
       </tr>
</table>
字体红色的怎么实现,我自己写的不对。 Struts2 计划 --------------------编程问答--------------------
Quote: 引用 楼主 liucong6517 的回复:

<s:hidden name="bean.planget"/>
<table class="tableStyle" width="60%" align="center" cellpadding="0px" cellspacing="0px"
style="margin-left:auto;margin-right:auto">
    <tr>
     <th align="right"><b>计划名称<span class="red">*</span></b></th>     
        <td align="left">
         <s:textfield name="bean.planInfoName" id="planInfoName" maxlength="20" />
         <span id="planInfoNameNull" class="red"> </span>
         </td>
    </tr>
<tr>
     <th width="18%" align="right"><b>计划条数<span class="red">*</span></b></th>       
        <td align="left">
         <s:textfield name="bean.planInfoNum" id="planInfoNum" maxlength="20" />
         <span id="planInfoNumNull" class="red"> </span>
      </td>
    </tr>
     <tr>
     <th align="right"><b>计划时间<span class="red">*</span></b></th>
        <td align="left">
         <s:textfield name="bean.planInfoTime" id="planInfoTime" maxlength="20"  onClick="WdatePicker()" class="Wdate" />
                          <span id="planInfoTimeNull" class="red"> </span>
        </td>
     </tr>
     <tr>
     <th align="right"><b>承办领导</b></th>
        <td>        
         <s:textfield name="bean.planInfoMyPL" id="planInfoMyPL" maxlength="20" />
        </td>
     </tr>
     <tr>
     <th align="right"><b>责任单位承办人<span class="red">*</span></b></th>
        <td align="left">
         <s:textfield name="bean.planInfoPeople" id="planInfoPeople" maxlength="20" />
        </td>
     </tr>
     <tr>
     <th align="right"><b>完成时间<span class="red">*</span></b></th>
        <td align="left">
         <s:textfield name="bean.planInfoOKTime" id="planInfoOKTime" maxlength="20"  onClick="WdatePicker()" class="Wdate"/>
                  <span id="planInfoOKTimeNull" class="red"> </span>
        
        </td>
     </tr>
     <tr>
     <th align="right"><b>建议</b></th>
        <td align="left">
         <s:textarea name="bean.idea"/>
                  <span id="ideaNull" class="red"> </span>
        </td>
     </tr>  
     <tr>
     <th align="right"><b>计划内容<span class="red">*</span></b></th>
        <td align="left">
         <s:textarea name="bean.planInfoDetail" id="planInfoDetail"/>
                  <span id="planInfoDetailNull" class="red"> </span>
        </td>
     </tr>  
     <tr>
     <th align="right"><b>备注</b></th>
        <td align="left">
         <s:textarea name="bean.remark"/>
        </td>
        
     </tr>  
      <tr>
       [color=#FF0000] <th align="right"><b>计划撰写人</b></th>
        <td align="left">
            <s:textarea name="bean.planset" value="#session.user.getRealName()"/>
           </td>
           </tr>[/color]
      



 <tr>
        <th align="right"><b>计划撰写人</b></th>
        <td align="left">
            <s:textarea name="bean.planset" value="#session.user.realName"/>
           </td>
           </tr>
        
        <tr>
        <th align="right"><b>计划部门</b></th>
        <td align="left">
            <s:textarea name="bean.plan_dep" value="#session.user.department"/>
        </td>
       </tr>
--------------------编程问答-------------------- 不行 文本框运行之后直接显示#session.user.department获取不到参数 --------------------编程问答--------------------
引用 2 楼 liucong6517 的回复:
不行 文本框运行之后直接显示#session.user.department获取不到参数



  <s:textarea name="bean.planset" value="#session.user.realName"/>
这个能拿到吗 --------------------编程问答--------------------
引用 2 楼 liucong6517 的回复:
不行 文本框运行之后直接显示#session.user.department获取不到参数




如果能,把你的实体类贴出来看看 --------------------编程问答-------------------- public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null; --------------------编程问答-------------------- private int planId = 0;
    private int planInfoNum = 0;
    private String planInfoName = null;
    private String planInfoTime = null;
    private String planInfoDetail = null;
    private String planInfoMyPL = null;
    private String planInfoPeople = null;
    private String planInfoTheyPL = null;
    private String planInfoOKTime = null;
    private String delFlag = null;
    private String idea = null;
    private String remark = null;
    private String planInfoType = "1";
    private String planset =  null;
    private String plan_dep = null; 
    private String planget = null; --------------------编程问答--------------------
引用 4 楼 q35335010 的回复:
Quote: 引用 2 楼 liucong6517 的回复:

不行 文本框运行之后直接显示#session.user.department获取不到参数




如果能,把你的实体类贴出来看看
private int planId = 0;
    private int planInfoNum = 0;
    private String planInfoName = null;
    private String planInfoTime = null;
    private String planInfoDetail = null;
    private String planInfoMyPL = null;
    private String planInfoPeople = null;
    private String planInfoTheyPL = null;
    private String planInfoOKTime = null;
    private String delFlag = null;
    private String idea = null;
    private String remark = null;
    private String planInfoType = "1";
    private String planset =  null;
    private String plan_dep = null; 
    private String planget = null; --------------------编程问答--------------------
引用 5 楼 liucong6517 的回复:
public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null;



这两个类的所有属性都有getter  setter吧 --------------------编程问答--------------------
引用 8 楼 q35335010 的回复:
Quote: 引用 5 楼 liucong6517 的回复:

public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null;



这两个类的所有属性都有getter  setter吧

这个必须有的   --------------------编程问答--------------------
引用 9 楼 liucong6517 的回复:
Quote: 引用 8 楼 q35335010 的回复:

Quote: 引用 5 楼 liucong6517 的回复:

public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null;



这两个类的所有属性都有getter  setter吧

这个必须有的  





<s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/> 那你之前在页面怎么是这样写的啊  难道你User类的  getdepartment()是这样的        还是getDepartment()的 --------------------编程问答--------------------
引用 10 楼 q35335010 的回复:
Quote: 引用 9 楼 liucong6517 的回复:

Quote: 引用 8 楼 q35335010 的回复:

Quote: 引用 5 楼 liucong6517 的回复:

public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null;



这两个类的所有属性都有getter  setter吧

这个必须有的  





<s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/> 那你之前在页面怎么是这样写的啊  难道你User类的  getdepartment()是这样的        还是getDepartment()的

现在无论是getDepartment()还是getdepartment()文本框是直接显示#session.user.getdepartmt()不能显示user的部门,这是什么原因呢?value能不能直接调用#session.user.getdepartment()? --------------------编程问答-------------------- bean.planset" value="#session.user.getRealName()"/
把你的Action看看;
--------------------编程问答--------------------
引用 11 楼 liucong6517 的回复:
Quote: 引用 10 楼 q35335010 的回复:

Quote: 引用 9 楼 liucong6517 的回复:

Quote: 引用 8 楼 q35335010 的回复:

Quote: 引用 5 楼 liucong6517 的回复:

public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null;



这两个类的所有属性都有getter  setter吧

这个必须有的  





<s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/> 那你之前在页面怎么是这样写的啊  难道你User类的  getdepartment()是这样的        还是getDepartment()的

现在无论是getDepartment()还是getdepartment()文本框是直接显示#session.user.getdepartmt()不能显示user的部门,这是什么原因呢?value能不能直接调用#session.user.getdepartment()?




 方法名department的个头方法改成getDepartment()
然后在页面用  <s:textarea name="bean.plan_dep" value="#session.user.department"/>

--------------------编程问答--------------------
引用 11 楼 liucong6517 的回复:
Quote: 引用 10 楼 q35335010 的回复:

Quote: 引用 9 楼 liucong6517 的回复:

Quote: 引用 8 楼 q35335010 的回复:

Quote: 引用 5 楼 liucong6517 的回复:

public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null;



这两个类的所有属性都有getter  setter吧

这个必须有的  





<s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/> 那你之前在页面怎么是这样写的啊  难道你User类的  getdepartment()是这样的        还是getDepartment()的

现在无论是getDepartment()还是getdepartment()文本框是直接显示#session.user.getdepartmt()不能显示user的部门,这是什么原因呢?value能不能直接调用#session.user.getdepartment()?



  <s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/>
//你那样是取不到的


//正确的是这样
要把user对象里的department  的getter方法改成getDepartment()
在页面直接这样访问 <s:textarea name="bean.plan_dep" value="#session.user.department"/>
--------------------编程问答-------------------- <s:textarea name="bean.planset" value="#session.user.department"/>
改成value="${department}"  试试 --------------------编程问答--------------------
引用 14 楼 q35335010 的回复:
Quote: 引用 11 楼 liucong6517 的回复:

Quote: 引用 10 楼 q35335010 的回复:

Quote: 引用 9 楼 liucong6517 的回复:

Quote: 引用 8 楼 q35335010 的回复:

Quote: 引用 5 楼 liucong6517 的回复:

public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null;



这两个类的所有属性都有getter  setter吧

这个必须有的  





<s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/> 那你之前在页面怎么是这样写的啊  难道你User类的  getdepartment()是这样的        还是getDepartment()的

现在无论是getDepartment()还是getdepartment()文本框是直接显示#session.user.getdepartmt()不能显示user的部门,这是什么原因呢?value能不能直接调用#session.user.getdepartment()?



  <s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/>
//你那样是取不到的


//正确的是这样
要把user对象里的department  的getter方法改成getDepartment()
在页面直接这样访问 <s:textarea name="bean.plan_dep" value="#session.user.department"/>
还是不行!谢谢了 --------------------编程问答--------------------
引用 16 楼 liucong6517 的回复:
Quote: 引用 14 楼 q35335010 的回复:

Quote: 引用 11 楼 liucong6517 的回复:

Quote: 引用 10 楼 q35335010 的回复:

Quote: 引用 9 楼 liucong6517 的回复:

Quote: 引用 8 楼 q35335010 的回复:

Quote: 引用 5 楼 liucong6517 的回复:

public class User {
//涓婚敭鐢ㄦ埛id
    private int userId = 0;
    //鐢ㄦ埛瑙掕壊id
    private int roleId = 0;
    //鐢ㄦ埛鍚�
    private String userName = null;
    //瀵嗙爜
    private String userPassword = null;
    //濮撳悕
    private String realName = null;
    //鎬у埆 
    private String sex = null;
    //骞撮緞
    private String age = null;
    //澶囨敞
    private String remark = null;
  //鍒犻櫎鏍囧織浣�
    private String department = null;



这两个类的所有属性都有getter  setter吧

这个必须有的  





<s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/> 那你之前在页面怎么是这样写的啊  难道你User类的  getdepartment()是这样的        还是getDepartment()的

现在无论是getDepartment()还是getdepartment()文本框是直接显示#session.user.getdepartmt()不能显示user的部门,这是什么原因呢?value能不能直接调用#session.user.getdepartment()?



  <s:textarea name="bean.plan_dep" value="#session.user.getdepartment()"/>
//你那样是取不到的


//正确的是这样
要把user对象里的department  的getter方法改成getDepartment()
在页面直接这样访问 <s:textarea name="bean.plan_dep" value="#session.user.department"/>
还是不行!谢谢了



是不是根本就没有,或者是set方法是这样setdepartment();
你在放到session前,调试下看看是不是放到session里之前就没东西 --------------------编程问答--------------------
引用 15 楼 u010593193 的回复:
<s:textarea name="bean.planset" value="#session.user.department"/>
改成value="${"department}"  试试

直接报错"value" does not support runtime expressions --------------------编程问答--------------------
引用 18 楼 liucong6517 的回复:
Quote: 引用 15 楼 u010593193 的回复:

<s:textarea name="bean.planset" value="#session.user.department"/>
改成value="${"department}"  试试

直接报错"value" does not support runtime expressions




你在后台打印下user.department看看到底有没有
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,