woainan6042
2009-09-03 16:53 阅读 259
已采纳

struts取值问题

JSP页面:

Action

package cn.lxt.bgtoffice.actions;

import javax.servlet.http.*;

import cn.lxt.bgtoffice.beans.OfficeBw;
import cn.lxt.bgtoffice.beans.OfficeInfo;
import cn.lxt.bgtoffice.daos.OfficeBwDAO;
import cn.lxt.bgtoffice.daos.OfficeInfoDAO;
import cn.lxt.bgtoffice.forms.OfficeBwForm;
import cn.lxt.exceptions.*;
import cn.lxt.keys.Constants;
import cn.lxt.root.actions.*;
import org.apache.struts.action.*;

import java.text.SimpleDateFormat;
import java.util.*;

public class OfficeBwAddAction extends BaseAction {

public OfficeBwAddAction() {

}

/**

  • executeAction *
  • @param mapping ActionMapping
  • @param form ActionForm
  • @param request HttpServletRequest
  • @param response HttpServletResponse
  • @return ActionForward
  • @throws BaseException
  • @todo Implement this cn.lxt.root.actions.BaseAction method
    */
    public ActionForward executeAction(ActionMapping mapping, ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws
    BaseException {

    if(!this.isSessionValid(request)){
    request.setAttribute("errorkey", "sessionfail");
    return mapping.findForward(Constants.errorPage);
    }
    String flag=request.getParameter("flag");
    OfficeBw temp=new OfficeBw();
    OfficeBw oc=new OfficeBw();
    try {
    request.setAttribute("page", request.getParameter("page"));
    OfficeBwForm ocf=(OfficeBwForm)form;
    if(ocf.getBwbh()==null||ocf.getBwbh().equals("")){
    //建立数据连接
    OfficeBwDAO sDAO = new OfficeBwDAO();
    int taotal_row=0;
    int qihao=1;
    try{
    taotal_row=sDAO.getNewOrderNum();
    qihao=sDAO.getQiHao();
    } catch (Exception ex) {
    System.out.println("出现错误:" + ex.getMessage());
    } finally {
    sDAO.close();
    }
    String num="0000"+taotal_row;

          Date date = new Date();
          SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH:mm");
          num="["+sp.format(date).substring(0,4)+"]"+num.substring(num.length()-4);
          request.setAttribute("nums", num);
          request.setAttribute("time", sp.format(date));
          //提供期号代码
          request.setAttribute("qihao", qihao);
          return mapping.findForward("officeBwAddStart");
      }else{
          if(Constants.database.equals("oracle")){
    
              Date date=new Date();
              SimpleDateFormat sp = new SimpleDateFormat("yyyyMMddHHmmss");
              String sdates=sp.format(date).trim();
    
              Random random=new Random();
              String ran=sdates+Integer.valueOf(Math.abs(random.nextInt())%100).toString();
              oc.setId(ran);
          }
          oc.setBlqk(new String(ocf.getBlqk().getBytes("ISO-8859-1"), "gb2312"));
          oc.setBwbh(new String(ocf.getBwbh().getBytes("ISO-8859-1"), "gb2312"));
          oc.setFffw(new String(ocf.getFffw().getBytes("ISO-8859-1"), "gb2312"));
          oc.setLwjg(new String(ocf.getLwjg().getBytes("ISO-8859-1"), "gb2312"));
          oc.setMj(new String(ocf.getMj().getBytes("ISO-8859-1"), "gb2312"));
          oc.setNbyj(new String(ocf.getNbyj().getBytes("ISO-8859-1"), "gb2312"));
          oc.setNums(ocf.getNums());
          oc.setOfficetime(new String(ocf.getOfficetime().getBytes("ISO-8859-1"), "gb2312"));
          oc.setSldps(new String(ocf.getSldps().getBytes("ISO-8859-1"), "gb2312"));
          oc.setTldps(new String(ocf.getTldps().getBytes("ISO-8859-1"), "gb2312"));
          oc.setWjmc(new String(ocf.getWjmc().getBytes("ISO-8859-1"), "gb2312"));
          oc.setYwbh(new String(ocf.getYwbh().getBytes("ISO-8859-1"), "gb2312"));
          oc.setNbyj(oc.getNbyj().replaceAll("  ", "  "));
          oc.setTldps(oc.getTldps().replaceAll("  ", "  "));
          oc.setSldps(oc.getSldps().replaceAll("  ", "  "));
          //7个新增字段插入
          oc.setFawentype(new String(ocf.getFawentype().getBytes("ISO-8859-1"),"gb2312"));
          oc.setFawenyear(new String(ocf.getFawenyear().getBytes("ISO-8859-1"),"gb2312"));
          oc.setFawenhao(new String(ocf.getFawenhao().getBytes("ISO-8859-1"),"gb2312"));
          oc.setLianxiren(new String(ocf.getLianxiren().getBytes("ISO-8859-1"),"gb2312"));
          oc.setDianhua(new String(ocf.getDianhua().getBytes("ISO-8859-1"),"gb2312"));
          oc.setUserId(new String(ocf.getUserId().getBytes("ISO-8859-1"),"gb2312"));
          oc.setDeptId(new String(ocf.getDeptId().getBytes("ISO-8859-1"),"gb2312"));
          //建立数据连接
          OfficeBwDAO sDAO = new OfficeBwDAO();
          try {
    
              temp=sDAO.getOfficeBwByBwbh(oc.getBwbh());
              if(temp==null){
                  sDAO.addOfficeBw(oc);
                  temp=sDAO.getOfficeBwByBwbh(oc.getBwbh());
              }else{
                  oc.setId(temp.getId());
                  sDAO.updateOfficeBw(oc);
              }
          } catch (Exception ex) {
            System.out.println("出现错误:" + ex.getMessage());
          } finally {
            sDAO.close();
          }
      }
    

    } catch (Exception e) {

        e.printStackTrace();
    

    }

    OfficeInfoDAO iDAO = new OfficeInfoDAO();
    try{
    OfficeInfo oi=iDAO.getOfficeInfo();
    request.setAttribute("info",oi );
    } catch (Exception ex) {
    System.out.println("出现错误:" + ex.getMessage());
    } finally {
    iDAO.close();
    }

    request.setAttribute("fontsize", request.getParameter("fontsize"));

    request.setAttribute("lwjgsize", request.getParameter("lwjgsize"));

    if(flag.equals("1")){
    oc.setLwjg(oc.getLwjg().replaceAll("\r\n","
    "));
    // 这里可能导致行距加大oc.setWjmc(oc.getWjmc().replaceAll("\r\n","
    "));
    oc.setBwbh(oc.getBwbh().replaceAll("\r\n","
    "));
    oc.setYwbh(oc.getYwbh().replaceAll("\r\n","
    "));
    oc.setNbyj(oc.getNbyj().replaceAll("  ", " "));
    oc.setTldps(oc.getTldps().replaceAll("  ", " "));
    oc.setSldps(oc.getSldps().replaceAll("  ", " "));
    request.setAttribute("databean",oc);
    return mapping.findForward("pageprintbwone");
    }else if(flag.equals("2")){
    oc.setLwjg(oc.getLwjg().replaceAll("\r\n","
    "));
    oc.setWjmc(oc.getWjmc().replaceAll("\r\n","
    "));
    oc.setBwbh(oc.getBwbh().replaceAll("\r\n","
    "));
    oc.setYwbh(oc.getYwbh().replaceAll("\r\n","
    "));
    oc.setNbyj(oc.getNbyj().replaceAll("  ", " "));
    oc.setTldps(oc.getTldps().replaceAll("  ", " "));
    oc.setSldps(oc.getSldps().replaceAll("  ", " "));
    request.setAttribute("databean",oc);
    return mapping.findForward("pageprintbwtwo");
    }else{
    // return (mapping.findForward("officeBwAddEnd"));原跳转
    if(!oc.getWjmc().contains("font-family")){
    oc.setWjmc(""+oc.getWjmc()+"");
    }
    if(!oc.getWjmc().contains("font-size")){
    oc.setWjmc(""+oc.getWjmc()+"");
    }
    if(!oc.getSldps().contains("font-family")){
    oc.setSldps(""+oc.getSldps()+"");
    }
    if(!oc.getSldps().contains("font-size")){
    oc.setSldps(""+oc.getSldps()+"");
    }
    if(!oc.getTldps().contains("font-family")){
    oc.setTldps(""+oc.getTldps()+"");
    }
    if(!oc.getTldps().contains("font-size")){
    oc.setTldps(""+oc.getTldps()+"");
    }
    if(!oc.getNbyj().contains("font-family")){
    oc.setNbyj(""+oc.getNbyj()+"");
    }
    if(!oc.getNbyj().contains("font-size")){
    oc.setNbyj(""+oc.getNbyj()+"");
    }
    request.setAttribute("databean",oc );
    return mapping.findForward("pageprintbwone");
    }
    }
    }

取不到“号”的值
大家帮忙看看,小弟是新手

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

5条回答 默认 最新

  • 已采纳
    samungtered samungtered 2009-09-04 08:36

    楼上说的
    在页面上用 ${}这个是EL表达式

    至于楼主的问题
    应该是没set值吧

    貌似在struts2的迭代标签里面 都用%{}的ognl方式取值
    而webwork里面是可以的

    点赞 评论 复制链接分享
  • walsh_bupt walsh_bupt 2009-09-03 17:16

    OfficeBwForm这个类粘出来

    点赞 评论 复制链接分享
  • onlyzhaozhen onlyzhaozhen 2009-09-03 18:13

    你又没有传值啊?

    点赞 评论 复制链接分享
  • qwe_rt qwe_rt 2009-09-04 01:37

    楼主用下如下代码:

    [code="html"][/code]

    [code="html"][/code]
    [size=medium][color=cyan]
    一般$的使用在属性文件或xml文件中![/color][/size]

    点赞 评论 复制链接分享
  • qwe_rt qwe_rt 2009-09-04 14:03

    struts 2版本不推荐使用EL表达式!而是推荐使用OGNL语言。

    点赞 评论 复制链接分享

相关推荐