疑问:struts中条件tag的用法

今天,在写补充邮件系统的时候,碰到这么一个问题:

<c:if test="${requestScope['iSSendDiary']=='sendadvice'}">,

<c:if test="${requestScope['iSSendDiary']==sendadvice}">,

<c:if test="${requestScope['iSSendDiary']==true}">,

<c:if test="${requestScope['iSSendDiary']=='true'}">

这四种用法是不一样的,但我没有这方面的详细资料,这个问题留待以后解决。

为了稳当起见,我在没有弄清这四者的区别时,应尽量使用:

<c:if test="${requestScope['iSSendDiary']=='sendadvice'}">来进行判断。

添加新目标邮件通知之编码

1、因为在显示所有目标的时候会反复使用判断是否订阅的属性,把这个属性保存在session中,在LoginAction.java中得出;

2、看了IndexAction.java的头部注释,来自disall.jsp中的pageNum会被保存在session中,所以在订阅/退订新增目标通知时,不必传递pageNum参数了。

3、在集成了raorao邮件系统的V0.9.0.2.5的基础上所作的改变:

    1)、LoginAction.java,已订阅的isOrderNewGoal为true,未订阅为false。添加代码如下:

            //test if current user order the notice when someone adding new goal

if (myDB.isSubscribeMail(userInfo.getUserID(), 0))

{

  mySession.setAttribute("isOrderNewGoal", "true");

}else{

  mySession.setAttribute("isOrderNewGoal", "false");

}

 

    2)、disall.jsp,增加订阅/退订新增目标的链接,已订阅就显示退订,未订阅就显示订阅。中文页面。添加代码如下:

  <div align="center">

    <c:choose>

      <c:when test="${sessionScope['USERINFO'].userID != -1 && sessionScope['isOrderNewGoal'] ==false}">

       <html-el:link action="toSubscribeMailAction.do?goalID=0">

        当有新增目标请用邮件通知我

       </html-el:link>

      </c:when>

      <c:when test="${sessionScope['USERINFO'].userID != -1 && sessionScope['isOrderNewGoal'] == true}">

       <html-el:link action="toCancelMailAction.do?goalID=0">

        当有新增目标请不要通知我

       </html-el:link>

      </c:when>

    </c:choose>

  </div>

    3)、为了增强可理解性,改变raorao修改过的DisGoalContentAction.java,订阅了相应属性为true,否则为false;

    4)、改变raorao修改过的disGoalContent.jsp,同3),订阅为true显示退订链接,否则显示订阅链接;

    5)、在application.properties中增加了下列内容:

      # -- order mail:created by admin at 2004-12-5 20:48:20 --

      mail.orderNewGoal =当有新增目标请用邮件通知我

      mail.cancelNewGoal =当有新增目标请不要通知我

     

      # -- select after posting goal:created by admin at 2004-12-7 13:01:03  --

      afterpostgoal.viewgoal =查看您刚才提交的目标

      afterpostgoal.select =提交新目标后的选择:

     

      # -- select after posting advice of goal:created by admin at 2004-12-7 13:01:03  --

      afterpostadvice.viewadvice =查看您刚才提交的评论

      afterpostadvice.viewallgoal =查看所有目标列表

    6)、在struts-config.xml的action    path="/toSubscribeMailAction"中和action    path="/toCancelMailAction"分别添加了     <forward

name="newGoalSuccess" path="/indexAction.do" />,表示订阅/退阅新增目标通知后的定向是回到原来的“显示所有目标”页面。即为:

                <!-- created by raorao at 2004-11-28 21:53:42 -->

                <!-- edited by admin at 2004-12-7 9:59:45 -->

    <action    path="/toSubscribeMailAction"

    type="com.learndiary.website.action.disgoal.ToSubscribeMailAction">

     <forward name="success" path="/disGoalContentAction.do" />

     <forward name="newGoalSuccess" path="/indexAction.do" />

    </action>

   

                <!-- created by raorao at 2004-11-28 21:53:42 -->

                <!-- edited by admin at 2004-12-7 9:59:45 -->

<action    path="/toCancelMailAction"

type="com.learndiary.website.action.disgoal.ToCancelMailAction">

     <forward name="success" path="/disGoalContentAction.do" />

     <forward name="newGoalSuccess" path="/indexAction.do" />

    </action>

因为在session中已有pageNum参数,所以不必传递这个参数;

修改了raorao编辑过的action    path="/postAdviceAction",     <forward name="goalSuccess" path="/processGoalAction.do" />变为

     <forward name="goalSuccess" path="/toSendMailOfGoalAction.do" />;

增加了     <forward name="isBackSubmitGoal" path="/processGoalAction.do?pageNum=1"/>,用于防止重复发送新增目标邮件。

    7)、修改了raorao写的ToCancelMailAction.java和ToSubscribeMailAction.java,因为新加了订阅/退订新增目标通知的定向,将原来的return mapping.findForward("success");改为:

    if (goalID == 0)

      return mapping.findForward("newGoalSuccess");

    else

      return mapping.findForward("success");

    因为会在try块外使用goalID,所以把下列这块代码移到try块以前:

    String goalIDStr = request.getParameter("goalID");

    int goalID = Integer.parseInt(goalIDStr);

    另外,当改变订阅状态后,应该把session里的isOrderNewGoal改变,在ToCancelMailAction.java里加上:      if (goalID == 0)

        request.getSession().setAttribute("isOrderNewGoal", "false");

在ToSubscribeMailAction.java里加上:      //when ordering notice of adding new goal,change the "isOrderNewGoal" attribute value in session

      request.getSession().setAttribute("isOrderNewGoal", "true");

    8)、在PostAdvice0Action.java和PostAdviceAction.java中增加了生成新目标的内容和防止重复发送新目标的内容:

        if (typeID==1){

              ArticleInfo articleInfo = new ArticleInfo();

      articleInfo.setArticleName(articleName);

      articleInfo.setArticleText(articleText);

      articleInfo.setArticleResource(articleResource);

      request.getSession().setAttribute("articleInfoOfDiary",articleInfo);

      request.getSession().setAttribute("MailOfGaol", "0");

      request.getSession().setAttribute("typeIDStr", typeIDStr);

    }

和:else if (typeID == 1) {

        target = "isBackSubmitGoal";

      }

在这两个文件中,typeID表示所提交文章的类型,goalID表示所提交文章的父文章(parent)的ID。

    9)修改了raorao写的ToSendMailOfThread.java,在方法 public String getGoalName() 中添加了:   if (goalID == 0)

     return "当有新增目标请用邮件通知我";

还添加了:

else if(typeID==1){

       bodyTextBuffer.append(" 添加了如下新目标: \n");

   }

    10)、修改了raorao写的ToSendMailOfGoalAction.java,添加了如下代码

    :else if (typeID==1)

{

          request.setAttribute("iSSendDiary","sendgoal");

}

    11)、修改raorao写的disUserOfmail.jsp,添加提交并发送新增目标后的选择去向,并添加了一些其它提交后的去向:

      <c:when test="${requestScope['iSSendDiary']==sendgoal}">

<html-el:link action="disGoalContentAction.do?goalID=${requestScope['postedArtID']}">

查看您刚才提交的目标

</html-el:link><p>

        <html-el:link action="processGoalAction.do?pageNum=1">

撰写日记

</html-el:link>

      </c:when>

 

我准备写的邮件系统补充订阅新增目标的设计

为了方便大家在有人添加了一个新目标后可以得到通知,在raorao写的邮件系统基础上,我准备添加当用户提

交一个新目标发送邮件的功能。下面是我的设计思路:

1、订阅和退订新增目标通知在主页上disall.jsp,判断是是否订阅的值在进入disall.jsp之前的

IndexAction.java中得出,利用raorao写的LearnDiaryDB.java中public boolean isSubscribeMail(int

userID,int goalID)来进行;然后把得出的值存在session的属性"isOrderNewGoal"中供用户进入disall.jsp中

使用;

2、当isOrderNewGoal == true时,显示退订的链接;否则显示订阅的链接;

3、订阅新目标通知和退订新目标通知使用raorao写的

com.learndiary.website.action.disgoal.ToSubscribeMailAction;

com.learndiary.website.action.disgoal.ToCancelMailAction

为了在改变订阅状态后页面内容保持不变,应该把当前显示目标的页码保存在request中,当改变订阅状态成功

后,定向到indexAction中,然后显示对应的页面;

4、当用户新增一个目标提交后用raorao写的发送目标下的评论的方式发送邮件。只不过提交日记成功后的定

向是processGoalAction.do。

文档是这样写的吗?

我还没写过文档,请问大家,是这样写的吗?

这就是我写发送邮件的那个程序的文档

位置:package com.learndiary.website.action.sendmail

整体描述:实现Runnable接口,运行在后台发送邮件的线程

成员变量:

  private ArrayList userInfoList 订阅了此目标的所有用户

private ArticleInfo articleInfo 需发送的日记

private int goalID 目标goalID

private String userNameOfWriteDiary 写日记用户的用户名

成员方法:

  public String getGoalName() 返回目标的Name

  局部变量:

  goalName = myDB.getGoalNameByID(goalID); 通过goalID返回目标的Name

        

  public void run() 线程里的run方法

  局部变量: 

  EmailAuthenticator mailAuthenticator = new EmailAuthenticator(uername,password); 获得SMTP邮件服务器认证.

  Properties props = System.getProperties();  获得系统属性

  props.put("mail.smtp.host",host); 设置邮件服务器

  props.put("mail.smtp.auth","true"); 设置邮件服务器

  Session session = Session.getInstance(props,(Authenticator)mailAuthenticator); 获得会话

  String toMail = userInfo.getEmail();  获得订阅了此目标用户的邮箱(收信地址)

  String userName = userInfo.getUserName(); 获得订阅了此目标用户的用户名

  Session session = Session.getInstance(props,(Authenticator)mailAuthenticator); 获得会话

  MimeMessage message = new MimeMessage(session);  定义消息

  message.setFrom(new InternetAddress(from)); 设置发信人

  message.addRecipient(Message.RecipientType.TO,new InternetAddress(toMail)); 设置收信人

  message.setSubject("学习日记您订阅的目标日记"); 设置消息主题

  message.setText("您好!"+userName+bodyText); 设置消息内容

  transport.connect(host,uername,password); 链接SMTP邮件服务器

  transport.sendMessage(message,message.getAllRecipients()); 发送消息

  transport.close(); 关闭连接

增加订阅邮件功能已完成

我把发送邮件的原代码贴出来

public class ToSendMailOfThread implements Runnable{

private ArrayList userInfoList = null;

private ArticleInfo articleInfo=null;

private int goalID ;

private String userNameOfWriteDiary = null;

    ToSendMailOfThread(ArrayList userInfoList,ArticleInfo articleInfo,int goalID,String userNameOfWriteDiary){

    this.userInfoList = userInfoList;

this.articleInfo = articleInfo;

this.goalID = goalID;

this.userNameOfWriteDiary = userNameOfWriteDiary;

    }

 public String getGoalName() {

   String goalName =null;

  try{

LearnDiaryDB myDB = new LearnDiaryDB();

goalName = myDB.getGoalNameByID(goalID);

}catch (Exception e){  

e.printStackTrace();

return goalName;

     }

     return goalName;

 }

 public void run(){

  String host = "smtp.126.com";

  String from = "learndiary@126.com";

  String uername = "learndiary";

  String password = "123456";

  UserInfo userInfo = null;

  String goalName = getGoalName();

  java.sql.Timestamp now = new java.sql.Timestamp(System.currentTimeMillis());

  StringBuffer bodyTextBuffer = new StringBuffer() ;

       bodyTextBuffer.append("\n");

   bodyTextBuffer.append("关于学习目标:");

   bodyTextBuffer.append(goalName);

   bodyTextBuffer.append("\n");

   bodyTextBuffer.append(userNameOfWriteDiary);

   bodyTextBuffer.append(" 在 ");

   bodyTextBuffer.append(now);

   bodyTextBuffer.append(" 写了如下日记: \n");

       bodyTextBuffer.append("---------------------------------------------------------------- \n");

   bodyTextBuffer.append("标题: ");

   bodyTextBuffer.append(articleInfo.getArticleName());

   bodyTextBuffer.append("\n");

   bodyTextBuffer.append("内容: ");

   bodyTextBuffer.append(articleInfo.getArticleText());

   bodyTextBuffer.append("\n");

   bodyTextBuffer.append("相关资源: ");

   bodyTextBuffer.append(articleInfo.getArticleResource());

   bodyTextBuffer.append("\n");

   bodyTextBuffer.append("---------------------------------------------------------------- \n");

   bodyTextBuffer.append("欢迎常来学习日记!  http://www.learndiary.com");

   bodyTextBuffer.append("\n");

   String bodyText = bodyTextBuffer.toString();

   EmailAuthenticator mailAuthenticator = new EmailAuthenticator(uername,password);

   Properties props = System.getProperties();

   props.put("mail.smtp.host",host);

   props.put("mail.smtp.auth","true");

       Iterator iterator = userInfoList.iterator();

       while(iterator.hasNext()){

       userInfo=(UserInfo)iterator.next();

   String toMail = userInfo.getEmail();

   String userName = userInfo.getUserName();

         try{

Session session = Session.getInstance(props,(Authenticator)mailAuthenticator);

MimeMessage message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));

message.addRecipient(Message.RecipientType.TO,new InternetAddress(toMail));

message.setSubject("学习日记您订阅的目标日记");

message.setText("您好!"+userName+bodyText);

message.saveChanges();

Transport transport = session.getTransport("smtp");

transport.connect(host,uername,password);

transport.sendMessage(message,message.getAllRecipients());

transport.close();

//System.out.println("已发送一封邮件:"+toMail);

       } catch (Exception e){

  e.printStackTrace();

       }

   }//end of while

  }//end of run()

}

导航改进未能如期完成--很抱歉

自接到任务以后,我做了认真的分析和设计。

但是迫于能力有限,--我接触jsp还刚刚到jstl,

我曾于前几天和jw和admin联系反映过我的情况,得到admin的热情回复。

虽然这几天我已经尽力了,但是对于没能完成任务,影响到了整个项目的进度,我很遗憾,向各位成员道歉。

如果有好的人选,我愿意让贤。

订阅邮件功能的工作进度

编写代码已经完成,现正在完善文挡和写解决问题的过程的日记.

按大兴的建议,参照大富翁论坛。设计情况大概是这样:进入"显示目标内容"前先判断用户是否订阅了这个目标,没订就显示"订阅邮件",否则显示"取消邮件"。用户提交日记后,日记存入数据库后显示一个页面"订阅这个目标的用户有***",而发送邮件由后台处理,发送邮件的确比较费时间。为了试验申请了N个邮箱....

呵呵,今晚睡觉

改进导航能力初步构思。

在参考了admin和jw的意见之后,对改进导航能力有初步构思如下:

以下内容为添加的部分:

1,在具体某一日记中,添加两个链接“本目标的上一篇日记”和“本目标的下一篇日记”。

2,在具体某个“显示目标内容”中,添加“查看该目标日记”和“返回目标列”。

以下内容为修改的部分:

1,从目标列打开“显示目标内容”,由原来的在新浏览器窗口改为在当前窗口打开

这只是在原先基础上的小修小补,一方面是因为这是探索性的试探,另一方面也有我自身能力的原因

各位有什么看法都来说说。

改进导航--此导航非彼导航

23日收到jw的邮件,获悉自己的任务如下:

        4)改善系统的导航功能:目前的系统导航能力太差,以www.javaresearch.org为样板改善系统的导航功能;

功能完成者:poemco 时间7天(3天设计)

 我在做分析的时候,有几点疑惑 :

          1,什么是导航?

          2,改善导航意味着我可以做什么改动?“以www.javaresearch.org为样板”意味着我不能做什么?

对于这两个问题,我也有自己的看法,但是为避免理解偏差,和各位沟通一下,

         1,导航是指页面的跳转,链接是其实现手段。导航不是简单的后退。

               我认为网站资源(页面)是一个层次关系,比如在“您的目标”的页面中,我看以看到“进行中的目标”,“已完成的目标”,“已退出的目标”。然后我在“进行中的目标”页面中,我可以看到“精读《jsp2.0技术手册》”和“学习日记.......”这两个目标。那么我在子层次页面中可以点击按钮返回到上级层次中,这是上级层次和子层次间的导航,如果我在某个目标下查看某一篇日记,那么我也可以不必返回到上级层次-目标,就可以通过点击链接,看到下一篇或上一篇日记,这是同层次间的导航。

         2,对于第二个问题,也是我对自己权限的疑问。

               比如,按照我的构想,当用户登陆以后,在第一个页面,他应该可以看到“您的目标”,“所有目标”,“控制面板”三个栏目。如果这样的话,我需要把给我写信,帐号管理等归在新创建的“控制面板”去。但是这样的话,我怕整个项目会乱套了。