Skip to content

Instantly share code, notes, and snippets.

@ToanPV90
ToanPV90 / doPost vs doGet Servlet
Last active October 29, 2018 16:54
doPost vs doGet Servlet
Introduction
You should use doGet() when you want to intercept on HTTP GET requests. You should use doPost() when you want to intercept on HTTP POST requests. That's all. Do not port the one to the other or vice versa (such as in Netbeans' unfortunate auto-generated processRequest() method). This makes no utter sense.
GET
Usually, HTTP GET requests are idempotent. I.e. you get exactly the same result everytime you execute the request (leaving authorization/authentication and the time-sensitive nature of the page —search results, last news, etc— outside consideration). We can talk about a bookmarkable request. Clicking a link, clicking a bookmark, entering raw URL in browser address bar, etcetera will all fire a HTTP GET request. If a Servlet is listening on the URL in question, then its doGet() method will be called. It's usually used to preprocess a request. I.e. doing some business stuff before presenting the HTML output from a JSP, such as gathering data for display in a table.
@WebServlet("/products
@ToanPV90
ToanPV90 / Java8DateTimeExamples.java
Created August 22, 2017 03:54 — forked from mscharhag/Java8DateTimeExamples.java
Examples for using the Java 8 Date and Time API (JSR 310)
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import static java.time.temporal.TemporalAdjusters.*;
public class Java8DateTimeExamples {
1. Run command sudo apt-get install maven, to install the latest Apache Maven.
2. Run command mvn -version to verify your installation.
3. Where is Maven installed?
The command apt-get install the Maven in /usr/share/maven.
$ls -ls /usr/share/maven
total 16
4 drwxr-xr-x 2 root root 4096 Dec 7 01:28 bin
4 drwxr-xr-x 2 root root 4096 Dec 7 01:28 boot
0 lrwxrwxrwx 1 root root 10 May 28 2012 conf -> /etc/maven
mvn eclipse:eclipse -DdownloadSources -DdownloadJavadocs
1. Create file /home/{username}/.local/share/applications/eclipse.desktop
2. Next, copy and paste the content below into the file and save
[Desktop Entry]
Name=Eclipse JEE Oxygen
Type=Application
Exec=/home/{username}/eclipse/jee-oxygen/eclipse/eclipse
Terminal=false
Icon=/home/{username}/eclipse/jee-oxygen/eclipse/icon.xpm
Comment=Integrated Development Environment
@ToanPV90
ToanPV90 / gist:52e151c6916a3d4ec175b6b81c9d2ee0
Created February 23, 2019 04:07
unstage files with git
# new file: to-be-added
# modified: to-be-modified
# deleted: to-be-removed
#
me$ git reset -q HEAD to-be-added
# ok
me$ git reset -q HEAD to-be-modified
Step 1 – Add Node.js PPA
Node.js package is available in LTS release and the current release. It’s your choice to select which version you want to install on the system as per your requirements. Let’s add the PPA to your system to install Nodejs on Ubuntu.
Use Current Release: At te last update of this tutorial, Node.js 11.4.0 is the current Node.js release available.
sudo apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
Use LTS Release : At the last update of this tutorial, Node.js 10.14.1 is the LTS release available.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\033[1m\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\033[0m $ "
So we decide to remove the mysql server and reinstall again, below are the step that we were done.
sudo apt-get remove --purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
@ToanPV90
ToanPV90 / SAMLServlet.java
Created April 30, 2019 14:27 — forked from jimhe/SAMLServlet.java
Servlet to handle SAML Auth request and response. on GET /saml, it will redirect to the ID Provider with the proper SAMLRequest parameter. on POST /saml, it will parse the POST parameter for a properly signed and successful response before allowing the user in.
package com.comprehend.servlet;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.opensaml.Configuration;
import org.opensaml.common.binding.BasicSAMLMessageContext;
import org.opensaml.common.xml.SAMLConstants;
import org.opensaml.saml2.binding.decoding.HTTPPostDecoder;
import org.opensaml.saml2.binding.encoding.HTTPRedirectDeflateEncoder;
import org.opensaml.saml2.core.*;