WebServlet cannot be resolved to a type

WebServlet annotation is introduced in Servlet 3.0, it’s used to simplify the servlet creation (we don’t need to define it and its URL mapping in web.xml)

The WebServlet annotation usage is

e.g.

Then the user can visit /servlet/GetMailFileOwner to access this servlet

 

But today I met a problem with using WebServlet annotation. First I added WebServlet on the Linux machine (Eclipse Luna), and switched to another Windows machine (MyEclipse), then I tried to rebuild the project, I got following error:

On the Windows machine, I use the default servlet.jar which is added when I create the new Dynamic Web Project. But I replaced the default servlet.jar file with Tomcat 8.0 libraries.

So the solution is to add Tomcat 8.0 libraries to Java Build Path (We need first download Tomcat 8.0 and set it up for Eclipse, otherwise Eclipse will not find this Tomcat 8.0 libraries)

HTML set checkbox as readonly

Sometimes we don’t want to make some form fields non-editable to users, like Product ID, Order Created Date, Post Author, etc.

For HTML text input and textarea controls, we can add “readonly” attribute to disallow users to modify their value, but this attribute will not work for checkbox control. So how should we disable the checkbox (or set it as readonly)? The “disabled” attribute will do the job

(It works for both radio box and checkbox)

 

You will see following checkbox and radio button is disabled:


Fabric.js set text color

Fabric.js is a powerful javascript canvas library which wraps html5 canvas operation, and introduces objects (text, shape, path, etc.) to developer.

There is a common method set() for object, it can be used to set property of an object. But if you want to change text color, text.set(‘color’, ‘#0f0′) will not work.

To set color of text, we need modify the fill attribute or use setColor() method (only available for text object)

Or

 

 

The URL is not accessible when installing Magento

When installing Magento, we may get such error “The URL is not accessible”.

In some earlier versions of Magento, we can fix this problem by change code of app/code/core/Mage/Install/Model/Installer/Config.php
Just change

to

Will solve the problem. It’s because that the URL rewriting doesn’t work for some reasons. (Magento uses .htaccess files to add URL rewriting rules)

 

But in Magento 1.9, checking the “Skip the base url validation” option will solve this problem

Set sorting layer in unity c#

Sorting layer is a property of SpriteRenderer, it’s used to specify which object is at top, and which object is at bottom.

If you want to change the sorting layer in script, you can use following code:

 

 

Access PHP built-in web server from other devices

We often use following command to start the PHP built-in web server.

php -S localhost:port

But in this way only the machine which starts the server can access it, any other computers cannot access it.
To solve this problem, we can use 0.0.0.0 as the binding IP address

php -S 0.0.0.0:8000

Then other devices are able to access our server as well. Using 0.0.0.0 as the IP addres will make the server bind all available IP addresses on the machine.

No module named Crypto.PublicKey

When I tried to import the “paramiko” module, I got following error:

No module named Crypto.PublicKey

That means we need to install pycrypto library. Run following command to install pycrypto library by using pip:

In the installation I got a different error message:

error: Unable to find vcvarsall.bat

That means we need a C compiler to compile this extension. But we can also download a pre-built extension for windows: http://www.voidspace.org.uk/python/modules.shtml#pycrypto

 

After installing this extension and tried to import “paramiko” module, I got the error “No module named Crypto.PublicKey” again. We should rename “crypto” directory under “Lib/site-packages” to “Crypto”, then importing paramiko will work.

Drupal user properties (status, hostname, etc)

In Drupal, user_load($uid) function will return an user object. And Drupal has defined a global user object as well (it represents current logged in user).

The user object has following properties:

status -> active/blocked
uid -> user id
mail -> email address
created -> created timestamp
login -> login timestamp
hostname -> ip address
init -> the email address provided at initial registration
roles -> roles assigned to this user

The difference between “mail” property and “init” property is that mail can be changed after registration, but init is the first used email address and cannot be changed. If you want to send email to an user, you need to know his email address ($user->mail).

Unable to find vcvarsall.bat when installing gmpy using pip

GMPY is a multiple-precision arithmetic module, which is a extension module written by C. I tried to install it by using pip, then I got following error message:

Unable to find vcvarsall.bat

It’s because it’s trying to find a c compiler (Visual C++ or MinGW) to compile this extension but failed. To fix this error, one method is to install a C compiler (Visual C++ or MinGW). And another easier way is to download an windows installer: https://code.google.com/p/gmpy/downloads/list

Drupal search without reindex

In Drupal, if you want to let your published node appear in search results, you need to re-index the search first (Administration->Configuration->Search Settings). And the Drupal cron job file (cron.php) will be executed to re-index the site at a specific time on every minute, every hour or every day, etc.

But recently I’m building a project outsourcing site, I need the newly posted project can be searched by other users immediately after it’s published. I searched on Google and Drupal for a while, finally I found this module: Auto-Index.

This module will automatically re-index the nodes every time a new node is created or an existing node is edited. And there is no more configuration needed after installing.