每日记载内容总结5

1.url重复使用,可以编写一次然后引用:

<s:url namespace="/catalog" action="product" id="url" escapeAmp="false"> <!--escapeAmp="false"传递多个参数时需要加上,除去链接参数之间的&amp -->
        <s:param name="product.productId" value="productId"/> <!--name即为所传入的参数,value为参数的值 -->
</s:url> 
<a href="<s:property value="#url"/>">

2.关于数据库表格的级联删除以及级联更新操作:

alter table a
   add constraint FK_OA_REDB foreign key (studentID)
      references student(uid)
         on update cascade on delete cascade --赋予级联删除和级联更新

1.       Cascade:更新或删除父表时,所有子记录更新或删除
2.       Restrict:阻止父表更新或删除
3.       Set Null:更新或删除父记录时,将子记录中的外键设为NULL。
4.       No Action:不执行完整性限制
5.       Set Default:更新或删除父表时,将子记录中的外键设置为默认值

3.一些常见错误以及解决方案:

javax.servlet.jsp.PageContext cannot be resolved to a type
javax.servlet.jsp.JspException cannot be resolved to a type

要加servlet-api.jar和jsp-api.jar
WEB项目中出现The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in ei

jstl.jar 包在ide项目中有,但在tomcat发布的应用WEB-INF/lib下没有,这是工具发布项目的问题,复制一个jar包过去问题就解决了
用jstl调用java 方法报The function equals must be used with a prefix when a default namespace is not specified错误。
<c:if test="${user.userName.equals('admin')== true }">

answer:
    <c:set var="username_sp" value="<s:property value=\"user.userName.equals('admin')\"/>" />  
    <c:if test="${username_sp== true }"> 
出错:java.lang.IllegalStateException: getOutputStream() has already been called for this response 此错误出自用servlet创建验证码

JSP页面有一个隐式对象out,是由response的getWriter()产生的。 
而你现在又调用了response的getOutputStream(),但response的getWriter()与getOutputStream()是不应该同时使用的——这就是出现上边所示异常的原因。
因为JSP中百分百会先调用getWriter(),所以你可以考虑使用Servlet来实现图片下载的功能。 

在outputstream后面添加代码:out.clear();
out=pageContext.pushBody();即可解决

4.关于表单提交

  1.struts获取jsp里面bean的值,需要form提交 可用$("form").attr("action","addStudent.do");    $("form").submit();实现

  2.如果用js提交,只能获取其中一个的值,不能获取bean的值。

  3.name 里面加入bean'的名字,如student.studentName 在action里面get  set  studentName,依旧可以获取单独的studentName

  4.同一个表单的多种可能提交方式:

    办法1.同一个页面中建立两个表单 各自提交:

<form action="?" name="form1" id="form1">
 <!-- 表单内容 -->
<input type="submit" />
</form>
<form action="?" name="form1" id="form1">
 <!-- 表单内容 -->
<input type="submit"  />
</form>

    办法2:如果非要只有一个表单的话,通过js提交:

<script type="text/javascript" language="javascript">
function submitYouFrom(path){
 $('form1').action=path;
 $('form1').submit();
}
</script>
<form action="?" name="form1" id="form1">

 <!-- 表单内容 -->
<input type="button" value="提交1" onclick="submitYouFrom('地址一')"/>
<input type="button" value="提交2" onclick="submitYouFrom('地址二')"/>
</form>

5.其余的知识:

  1.用hql语句不能实现添加内容到表格。可以通过save方法实现。

  2.substring(2) 截取从第2个开始(不包括2)的剩下的所有字符
   subString(2,4)截取从第二个开始(不包括2)到第四个字符(包括4)也就是3 4

  3.索引合并的时候,不关闭IndexReader,将导致部分数据占用,从而合并的时候,多个cfs格式文件不能合并成一个。

6.schedule和scheduleAtFixedRate的区别:

在于,如果指定开始执行的时间在当前系统运行时间之前,scheduleAtFixedRate会把已经过去的时间也作为周期执行,而schedule不会把过去的时间算上。

比如

SimpleDateFormat fTime = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  Date d1 = fTime.parse("2005/12/30 14:10:00");
 
  t.scheduleAtFixedRate(new TimerTask(){
   public void run()
   {
       System.out.println("this is task you do6");
   }
  },d1,3*60*1000);

间隔时间是3分钟,指定开始时间是2005/12/30 14:10:00,如果我在14:17:00分执行这个程序,那么会立刻打印3次

this is task you do6     //14:10
this is task you do6     //14:13
this is task you do6     //14:16

并且注意,下一次执行是在14:19 而不是 14:20。就是说是从指定的开始时间开始计时,而不是从执行时间开始计时。

但是上面如果用schedule方法,间隔时间是3分钟,指定开始时间是2005/12/30 14:10:00,那么在14:17:00分执行这个程序,则立即执行程序一次。并且下一次的执行时间是 14:20,而不是从14:10开始算的周期(14:19)。

原文地址:https://www.cnblogs.com/cuiyf/p/3039151.html