Web 开发问题汇总(二)

1.Uncaught TypeError: Cannot read property ‘msie’ of undefined

A:The $.browser method has been removed as of jQuery 1.9.

jQuery.browser() removed

The jQuery.browser() method has been deprecated since jQuery 1.3 and is removed in 1.9. If needed, it is available as part of the jQuery Migrate plugin. We recommend using feature detection with a library such as Modernizr.

— jQuery Core 1.9 Upgrade Guide.

As stated in the Upgrade Guide you can try using the jQuery Migrate plugin to restore this functionality and let jQuery Tools work.

Reference:Uncaught TypeError: Cannot read property ‘msie’ of undefined - jQuery tools

2.The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path in Eclipse

A:To include http-servlet into your class path, you have two options:

1. In this solution, you can add desired server runtime into your application as project facet. As runtime servers have already servlet runtime dependencies, they get included into your project and hence error is gone.
2. Another option is include the servlet dependency through maven itself. This will also fix the error.
1
2
3
4
5
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>

Reference:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path in Eclipse

3.Dynamic Web Module 3.1 requires Java 1.7 or newer

A:

Step1:
Make sure your Java Project is configured probably to use Java 1.7. Right click your project > Properties > Java Compiler and set “Compiler compliance level” to 1.7

Step2:
Java Build Path. Click “Edit“. And change it to “Java 7”

Step3:
Next from the menu on the left select Project Facets > Java and set its version to 1.7

Extra Tips:
If you have maven project try updating source and target version of java compiler to 1.7 in pom.xml file.

Reference:How to solve “Dynamic Web Module 3.1 requires Java 1.7 or newer” in Eclipse

4.How to display available goals of maven plugin?

A:

Recent Maven plugins have generally an help goal to have in the command line the description of the plugin, with their parameters and types. For instance, to understand the javadoc goal, you need to call:

1
$ mvn javadoc:help -Ddetail -Dgoal=javadoc

It works of course for Maven core plugins. to list all goals of the archetype plugin :

1
$ mvn archetype:help

And it works also for third party plugins. For example, to display all goals of the spring-boot plugin :

1
$ mvn spring-boot:help

Reference:How to display a list of available goals?

5.Not a java source folder

A:以 maven-archetype-webapp 为原型新建工程,建好的工程没有 java 目录,于是在 src/main 下新建 java 目录,之后新建 Filter 或 Servlet 时提示 Not a java source folder.尝试右击 java 目录 > Build Path > Use as Source Folder 依然未生效,只得将目录删除恢复原状想其他办法。

于是选中工程 > Properties > Java Build Path > Source, 里面提示 src/main/java build path entries are missing, 嗯,有了新的线索,于是将这些丢失的入口都删除了,再重新创建 java source folder, 这样问题得到了解决,感觉这个问题像是 eclipse 的一个 bug.

继续阅读

How to Setup an IKEv2 VPN Server on CentOS 8

由于 Debian 8 官方不再支持,经过一番考虑和准备,最近将 VPS 的系统换成了 CentOS 8。Libreswan 的文档没有 VPN 时打不开,这就形成了一个死循环,所以将她换成了 StrongSwan 。StrongSwan 的文档个人觉得对新手不是很友好,我是看了好一会才看明白些,另外在支持 macOS,iOS,Windows 10 的过程中也遇到不少问题,所以这里记录下来,以备日后参考。

StrongSwan 的文档入口页有安装指南可用的配置示例。我个人建议先看下 Introduction to strongSwan,这对安装和配置很有帮助。

CentOS 8 中的 epel 仓库中有预编译的 strongswan 二进制安装包,我们直接安装就可以了。接下来就是配置,strongswan 有四种认证方式,出于安全和便捷的考虑,我选择了 Extensible Authentication Protocol (EAP)。

首先是准备证书。我们可以使用自签名证书或者通用证书颁发机构签发的证书,后者不需要在各个终端上安装自签名根证书,所以部署上更简单。

我们先来看看下自签名证书。

生成根证书:

1
2
3
cd /etc/strongswan/swanctl
strongswan pki --gen --outform pem > rsa/ca.pem
strongswan pki --self --ca --in rsa/ca.pem --type rsa --dn "C=CH, O=strongSwan, CN=strongSwan Root CA" --outform pem > x509ca/ca-cert.pem

生成服务器证书:

1
2
3
cd /etc/strongswan/swanctl
strongswan pki --gen --outform pem > rsa/server.pem
strongswan pki --pub --in rsa/server.pem --type rsa | strongswan pki --issue --cacert cacerts/ca.cert.pem --cakey rsa/ca.pem --dn "C=CH, O=strongSwan, CN=swan.tenneshop.com" --san swan.tenneshop.com --flag serverAuth --flag ikeIntermediate --outform pem > x509/server-cert.pem
继续阅读

圆锥渐变的一种简单实现

Core Graphics 支持两种渐变:线性(Axial)和径向(Radial)渐变,但是有的时候我们可能会用到圆锥(Conical)渐变,例如在扫描附近的目标时,交互可能用上带这种渐变的雷达效果,它长这样:


要实现这样一种渐变你会怎么做呢?我的想法是从渐变的本质着手。渐变是从一种颜色渐渐变化成另外一种颜色,而圆锥渐变是根据角度渐渐变化。我们把界面看成位图,这样可以由点的位置得到它的角度,继而根据角度线性插值可以得到它的颜色,最终就可以得到圆锥渐变。

想法有了,接下来我们用它来实现上图中 Find My iPhone 图标的雷达效果吧。

首先定义一个 CALayer 的子类 ConicalLayer,

继续阅读