爱知笔记

Zhizheng Zhang's Notes


  • 首页

  • 归档

  • 分类

  • 标签

  • 关于

  • 搜索

MyBatis 注解引发空指针异常

发表于 2017-12-26 | 分类于 MyBatis

数据库表字段含有下划线

field_name

Java 对象属性使用驼峰命名规则

fieldName

MyBatis 注解(错误)

@Select("select field_name from table_name")

MyBatis 注解(正确)

@Select("select field_name as fieldName from table_name")
阅读全文 »

js 获取父窗口中的元素

发表于 2017-12-20 | 分类于 JavaScript

通过原生 js 获取

window.parent.document.getElementById('elementId')

通过 jQuery 获取

$('#elementId', window.parent.document)

参考资料

  • How to get parent window element in jquery and JavaScript
阅读全文 »

Tomcat 降级导致 jsp 报错

发表于 2017-12-19 | 分类于 Tomcat

版本说明

原 tomcat 版本 7.0.82,新 tomcat 版本 7.0.52。

降级操作

采用覆盖安装方式。

报错信息

通过浏览器访问 tomcat 中部署的 web 程序 jsp 页面,报错信息如下:

java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagInfo

解决方案

删除 work/Catalina/localhost/<web 程序名称> 目录后,刷新浏览器,页面访问正常。

阅读全文 »

Linux screen 命令

发表于 2017-11-29 | 分类于 Linux

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. Each virtual terminal provides the functions of the DEC VT100 terminal and, in addition, several control functions from the ANSI X3.64 (ISO 6429) and ISO 2022 standards (e.g., insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows the user to move text regions between windows. When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill the current window, view a list of the active windows, turn output logging on and off, copy text between windows, view the scrollback history, switch between windows, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the users terminal.

阅读全文 »

Linux SSH 免密

发表于 2017-11-29 | 分类于 Linux

规划设定

  • 服务器:server1 server2 server3,其中 server1 是部署机,server2 server3 是目标机
  • 目标:服务器 server1 免密登录 server1 server2 server3(server1 免密登录 server1 是将 server1 也当成一个目标机使用)
  • 假定:所有主机使用用户名为 user

免密设置

# 在 server1 上生成公钥和私钥,下面演示使用 dsa 加密算法,还有 rsa 等加密算法,具体使用哪种请综合安全性等自行选择
user@server1:~$ ssh-keygen -t dsa
user@server1:~$ ls ~/.ssh
# id_dsa.pub # 公钥
# id_dsa     # 私钥

# server1 对 server1 免密
user@server1:~$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
user@server1:~$ chmod 600 ~/.ssh/authorized_keys
user@server1:~$ chmod 700 ~/.ssh

# server2 对 server1 免密
user@server1:~$ scp ~/.ssh/id_dsa.pub user@server2:/home/user/.ssh
user@server1:~$ ssh user@server2
user@server2:~$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
user@server2:~$ chmod 600 ~/.ssh/authorized_keys
user@server2:~$ chmod 700 ~/.ssh

# server3 对 server1 免密
user@server1:~$ scp ~/.ssh/id_dsa.pub user@server3:/home/user/.ssh
user@server1:~$ ssh user@server3
user@server3:~$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
user@server3:~$ chmod 600 ~/.ssh/authorized_keys
user@server3:~$ chmod 700 ~/.ssh

# 在 server1 上测试免密效果,以下直接登录,无需密码
user@server1:~$ ssh user@server1
user@server1:~$ ssh user@server2
user@server1:~$ ssh user@server3
阅读全文 »

Ganymed SSH-2 for Java 免密

发表于 2017-11-28 | 分类于 Java

Ganymed SSH-2 for Java 是一个纯 Java 实现的 SHH2 库,使用它可以通过用户密码登录服务器,那么是否可以免密登录呢?答案是可以的,而且支持 SFTP。

环境说明

  • java version: 1.7.0_79
  • Ganymed SSH-2: build251beta1

密码登录

String ip = "192.168.1.201";
int port = 22;
String username = "user";
String password = "passwrod";

Connection conn = new Connection(ip, port);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated){
    // 登录成功
} else {
    // 登录失败
}
阅读全文 »

Firefox 提示 libavcodec 过时

发表于 2017-11-21 | 分类于 Firefox

libavcodec may be vulnerable or is not supported, and should be updated to play video

环境说明

  • 操作系统:Debian 7 “Wheezy”(64-bit)
  • Firefox: 57.0 (64-bit)
  • FFmpeg: 3.4

解决方法

方法一:下载最新版 FFmpeg 源码,编译安装

./configure --prefix=/usr/local/ffmpeg ...
make
make install

vi /etc/ld.so.conf
# 添加一行
# /usr/local/ffmpeg/lib
ldconfig

方法二:修改 Firefox 参数

在地址栏中输入 about:config,将 media.libavcodec.allow-obsolete 的值由 false 修改为 true,重启浏览器。

方法三:安装 backports 源 libavcodec

系统原来带的是 libavcodec 53(53.35.0),现在安装 libavcodec 55(55.34.1)

apt-get install -t wheezy-backports libavcodec55
阅读全文 »

JSP 文件里 Integer 转 int 异常

发表于 2017-11-15 | 分类于 JSP
20171116 更新:Integer 和 int 是自动类型转化的,昨天的问题(int id = user.getId(); 异常)应该是 user 成员变量 id 没有初始化(如 User user = new User();)引起的。

Java 类 User.java

package com.test.bean;

public class User {

	private Integer id;
	private String name;

	public User() {
		super();
	}

	public User(Integer id, String name) {
		super();
		this.id = id;
		this.name = name;
	}

	public Integer getId() {
		return id;
	}

	public void setNId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
阅读全文 »

jQuery select2 设置初始值

发表于 2017-09-15 | 分类于 jQuery

jquery select2 设置初始值主要有两种方法,以下两种方法中,均设置 option 列表中第一个 option 为选中项。

方法一:给 option 元素添加 selected 属性

<select id="s2id">
   <option value="value1" selected="selected">text 1</option>
   <option value="value2">text 2</option>
</select>
$('#s2id').select2();

方法二:调用 js 给 select2 设置值

<select id="s2id">
   <option value="value1">text 1</option>
   <option value="value2">text 2</option>
</select>
var val1 = $('#s2id option:eq(0)').val();
$('#s2id').select2().select2('val', val1);
阅读全文 »

Chrome 中 span 无法撑开 a

发表于 2017-09-13 | 分类于 Chrome

在 blog 正文下面添加前一篇和后一篇按钮,遇到浏览器兼容问题。

问题描述

代码

<div class="pagination clearfix">
  <ul class="pull-right">
  {% if page.previous %}
    <li class="prev"><a class="fa fa-arrow-circle-left" href="{{ BASE_PATH }}{{ page.previous.url }}" title="{{ page.previous.title }}">前一篇</a></li>
  {% else %}
    <li class="prev disabled"><a class="fa fa-arrow-circle-left">前一篇</a></li>
  {% endif %}
    <li><a class="fa fa-th" href="{{ BASE_PATH }}{{ site.JB.archive_path }}">所有文档</a></li>
  {% if page.next %}
    <li class="next"><a href="{{ BASE_PATH }}{{ page.next.url }}" title="{{ page.next.title }}">后一篇<span class="fa fa-arrow-circle-right"></span></a></li>
  {% else %}
    <li class="next disabled"><a>后一篇<span class="fa fa-arrow-circle-right"></span></a>
  {% endif %}
  </ul>
</div>

期望结果

图片加载中......

阅读全文 »
1 2 3 4
Zhizheng Zhang

Zhizheng Zhang

Whatever u do, Remember why you started.

36 日志
18 分类
61 标签
RSS
GitHub
© 2025 Zhizheng Zhang
由 Jekyll 强力驱动
主题 - NexT.Mist