2018年5月28日 星期一

在樹莓派上使用no-ip動態域名的方法,也適用其它Linux平台

在樹莓派上使用no-ip動態域名的方法,也適用其它Linux平台

注意,如果沒有公網IP,本文的方法就不可行了。
首先,註冊一個noip.com的帳號
註冊的步驟見這篇教程:http://www.cnblogs.com/infopi/p/3991407.html
建立目錄
第1行進入當前用戶的home目錄
第2行建立noip子目錄,第3行進入noip子目錄
cd ~
mkdir noip
cd noip
下載noip客戶端源碼、安裝
第1行下載源碼,第2行解壓源碼,第3行進入解壓後的源碼目錄
第4行編譯,第5行安裝
wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar vzxf noip-duc-linux.tar.gz
cd noip-2.1.9-1
make
sudo make install
在安裝的過程中,會問以下問題
Please enter the login/email string for no-ip.com
(輸入註冊時填的郵箱地址)
Please enter the password for user
(輸入密碼)
Please enter an update interval: [30]
(noip客戶端檢查你路由器外部網址變化的間隔,默認是30分鐘)
(Increments in minutes that you want no-ip client to check if your router’s external dynamic IP address has changed and updates it accordingly.)
Do you wish to run something at successful update? [N] (y/N)
(直接按回車即可)
啟動noip客戶端,打這個命令:
sudo /usr/local/bin/noip2
要設置開機啟動,把上面這行加入/etc/rc.local,要加在exit 0那行以前
附兩個命令:
sudo /usr/local/bin/noip2 -C     重新配置一次(就是問安裝過程中那幾個問題)
sudo /usr/local/bin/noip2 -S      顯示當前運行狀態、信息
經驗:
no-ip網頁上寫著“免費域名只能用30天、且有廣告”,根據我的經驗是這樣的:
1、要保持郵箱暢通,以便點擊郵件裡的鏈接激活域名。
2、如果不使用80端口,不會遇到廣告。
3、某些國內ISP會每幾天強制斷線、更換IP,這時noip會短暫失效,失效時間取決於設置的刷新間隔(默認30分鐘)。
轉貼網址:http://www.cnblogs.com/infopi/p/3991437.html

2017年11月30日 星期四

QUESTION 109

When using the @WebListener annotation, the class on which the annotation is applied to must also implement
at least one o the following interfaces (Choose two):

A. RequestListener
B. AttributeListener
C. ServletContextListener
D. HttpSessionListener
E. SessionAttributeListener
F. AsyncListener

Correct Answer: CD
Explanation/Reference:
@WebListener
The main task of the listener is to listen the particular events and process your own task on that event. For
example, if you want to initialize a database connection before your application starts, ServletContextListener
will be implemented to do that. Another good example is -when you want to do some task on the creation and
destruction of a session. For this purpose you need to implement HttpSessionListener.

QUESTION 108

Which of following annotations can be used in a servlet class?
(i) @javax.annotation.Resource
(ii) @javax.annotation.PreDestroy
(iii) @javax.annotation.security.RunAs
(iv) @javax.annotation.security.RolesAllowed
(v) @javax.servlet.annotation.WebServlet

A. (v) only
B. (i) and (v)
C. (i), (ii), (iii) and (v)
D. (i), (ii), (iv) and (v)
E. (i), (ii), (iii), (iv) and (v)

Correct Answer: B
Explanation/Reference:
* (i) The javax.annotation.Resource annotation is used to declare a reference to a resource. @Resource can
decorate a class, a field, or a method.
* (v) javax.servlet.annotation
Annotation Type WebServlet
Annotation used to declare a servlet.
This annotation is processed by the container at deployment time, and the corresponding servlet made
available at the specified URL patterns.
Incorrect:
* Not (II) : javax.annotation.PreDestroy
Target: Method

QUESTION 107

Which of the following are attributes of the annotation javax.servlet.annotation.WebFiler?
(i) Name
(ii) servletNames
(iii) urlPatterns
(iv) dispatcherTypes
(v) supportAsync

A. (iii) only
B. (iii) and (iv)
C. (ii), (iii) and (iv)
D. (iii), (iv) and (v)
E. (ii), (iii), (iv) and (v)

Correct Answer: B
Explanation/Reference:
* (iii) urlPatterns
The URL patterns to which the filter applies
* (iv) dispatcherTypes
The dispatcher types to which the filter applies
* (not V): asyncSupported
Declares whether the filter supports asynchronous operation mode.
Note:
* javax.servlet.annotation
Annotation Type WebFilter
Annotation used to declare a servlet filter.
This annotation is processed by the container at deployment time, and the corresponding filter applied to the
specified URL patterns, servlets, and dispatcher types.

QUESTION 106

You have built a web application that you license to small businesses. The webapp uses a context parameter,
called licenseExtension, which enables certain advanced features based on your client's license package.
When a client pays for a specific service, you provide them with a license extension key that they insert into the
< context-param> of the deployment descriptor. Not every client will have this context parameter so you need to
create a context listener to set up a default value in the licenseExtension parameter.
Which code snippet will accomplish this goal?

A. You cannot do this because context parameters CANNOT be altered programmatically.
B. 
    String ext = context.getParameter(`licenseExtension');
    if ( ext == null ) {
        context.setParameter(`licenseExtension' DEFAULT);
    }
C.
    String ext = context.getAttribute(`licenseExtension');
    if ( ext == null ) {
        context.setAttribute(`licenseExtension' DEFAULT);
    }
D.
    String ext = context.getInitParameter(`licenseExtension')
    if ( ext == null ) {
        context.resetInitParameter(`licenseExtension' DEFAULT);
    }
E.
    String ext = context.getInitParameter(`licenseExtension')
    if ( ext == null ) {
        context.setInitParameter(`licenseExtension' DEFAULT);
    }

Correct Answer: A

QUESTION 105

Given the fragment from Java EE deployment descriptor:
341. <error-page>
342. <exception-type>java.lang.Throwable</exception-type> 343. <location>/mainError.jsp</location>
344. </error-page>
345. <error-page>
346. <exception-type>java.lang.ClassCastException</exception-type> 347. <location>/castError.jsp</location>
348. </error-page>
If the web application associated with the fragment above throws a ClassCastException.
Which statement is true?

A. The deployment descriptor is invalid.
B. The container invokes mainError.jsp
C. The container invokes castError.jsp
D. Neither mainError.jsp nor castError.jsp is invoked.

Correct Answer: C

QUESTION 104

Given a web fragment jar file, where should we put the web fragment.xml inside the jar file?

A. WEB-INF
B. META-INF
C. WEB-INF/lib
D. WEB-INF/classes
E. META-INF/services

Correct Answer: C
Explanation/Reference:
* If you're dealing with web applications, /WEB-INF/lib is the portable place to put JARs. This is where web
servers servlet containers expect to find an application's jar files.
* The /WEB-INF/classes directory is on the ClassLoader's classpath. This is where .class files are loaded from
when the web application is executing. Any JAR files placed in the /WEB- INF/lib directory will also be placed on
the ClassLoader's classpath.

QUESTION 103

Given the portion of a valid Java EE web application's directory structure:

image

You want to know whether File1.html, File2.html, and/or File3.html is protected from direct access by your web
client's browsers. What statement is true?


A. All three files are directly accessible.
B. Only File1.html is directly accessible.
C. Only File2.html is directly accessible.
D. Only File3.html is directly accessible.
E. Only File1.html and File2.html are directly accessible.
F. Only File1.html and File3.html are directly accessible.
G. Only File2.html and File3.html are directly accessible.


Correct Answer: B
Explanation/Reference:
Note:
* WEB-INF is the folder just under the root of a WAR that holds information that you don't want to be accessible
to a client via a URL request. Specifically, it holds the web.xml, classes, and lib directories, but you can put
anything you want to hide from the client there.
* META-INF is what discriminates a JAR file from a plain ZIP file. It holds the manifest file and may hold other
deployment information as needed.

QUESTION 102

A web application uses a cookies to track a client as it navigates through the pages that constitutes the
application. Which code snippet can be used by the web application to reduce the chance of a cross-site
scripting attack by setting some property of the cookie before returning it to the client?


A. cookie.setHttpOnly(true)
B. cookie.setMaxAge(3600)
C. cookie.setPath("/")
D. cookie.setSecure(true)


Correct Answer: A
Explanation/Reference:
When HTTPOnly flag is assigned to a cookie, the browser will restrict the access to such Cookie from Java
Script code hence the cookie would only be sent to the subsequent request to server but cannot be accessed
using client side script. In such a case even if website is vulnerable to Cross Site Scripting (XSS) attacks, still
the browser would safeguard the data stored into cookies flagged as HTTPOnly.
Incorrect:
Not D: If Secure flag is set for Cookie then it may only be transmitted over secure channel (SSL/HTTPS)
ensuring that data is always encrypted while transmitting from client to server.

QUESTION 101

Which java code snippet checks whether the user is of the role "MANAGER" for a given HttpServRequest,
httpServletRequest?


A. httpServletRequest.isUserInRole("MANAGER");
B. httpServletRequest.isCallerInRole("MANAGER");
C. httpServletRequest.isPrincipalInRole("MANAGER");
D. httpServletRequest.isAuthnticatedUserInRole("MANAGER");


Correct Answer: A


Explanation/Reference:
isUserInRole
public boolean isUserInRole(java.lang.String role)
Returns a boolean indicating whether the authenticated user is included in the specified logical "role". Roles and
role membership can be defined using deployment descriptors. If the user has not been authenticated, the
method returns false.
Parameters:
role - a String specifying the name of the role
Returns:
a boolean indicating whether the user making this request belongs to a given role; false if the user has not been
authenticated
Incorrect:
Not B: isCallerInRole is depreciated.