diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..7e93f22 Binary files /dev/null and b/.DS_Store differ diff --git a/AndroidActivity.rar b/AndroidActivity.rar new file mode 100644 index 0000000..2b5a6c9 Binary files /dev/null and b/AndroidActivity.rar differ diff --git a/AndroidAnimations.rar b/AndroidAnimations.rar new file mode 100644 index 0000000..4386487 Binary files /dev/null and b/AndroidAnimations.rar differ diff --git a/AndroidDatabaseExample.rar b/AndroidDatabaseExample.rar new file mode 100644 index 0000000..2dfb665 Binary files /dev/null and b/AndroidDatabaseExample.rar differ diff --git a/AndroidEventHandling.rar b/AndroidEventHandling.rar new file mode 100644 index 0000000..f0ebbad Binary files /dev/null and b/AndroidEventHandling.rar differ diff --git a/AndroidNotifications.rar b/AndroidNotifications.rar new file mode 100644 index 0000000..53d1262 Binary files /dev/null and b/AndroidNotifications.rar differ diff --git a/AndroidService.rar b/AndroidService.rar new file mode 100644 index 0000000..fbf120e Binary files /dev/null and b/AndroidService.rar differ diff --git a/EmailAttachmentExample.rar b/EmailAttachmentExample.rar new file mode 100644 index 0000000..2ea709b Binary files /dev/null and b/EmailAttachmentExample.rar differ diff --git a/FileUploaderJavaClient/README.md b/FileUploaderJavaClient/README.md new file mode 100644 index 0000000..72e6396 --- /dev/null +++ b/FileUploaderJavaClient/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/java-file-upload-rest-service diff --git a/FileUploaderRESTService/README.md b/FileUploaderRESTService/README.md new file mode 100644 index 0000000..72e6396 --- /dev/null +++ b/FileUploaderRESTService/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/java-file-upload-rest-service diff --git a/GlassfishFormBasedAuthentication/.classpath b/GlassfishFormBasedAuthentication/.classpath new file mode 100644 index 0000000..0cad5db --- /dev/null +++ b/GlassfishFormBasedAuthentication/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GlassfishFormBasedAuthentication/.gitignore b/GlassfishFormBasedAuthentication/.gitignore new file mode 100644 index 0000000..731eb43 --- /dev/null +++ b/GlassfishFormBasedAuthentication/.gitignore @@ -0,0 +1,2 @@ +/target/ +/.settings/ diff --git a/GlassfishFormBasedAuthentication/.project b/GlassfishFormBasedAuthentication/.project new file mode 100644 index 0000000..2a6d677 --- /dev/null +++ b/GlassfishFormBasedAuthentication/.project @@ -0,0 +1,37 @@ + + + GlassfishFormBasedAuthentication + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/GlassfishFormBasedAuthentication/.settings/.jsdtscope b/GlassfishFormBasedAuthentication/.settings/.jsdtscope new file mode 100644 index 0000000..e945e4e --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.core.resources.prefs b/GlassfishFormBasedAuthentication/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..cf6931b --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding/=UTF-8 diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.jdt.core.prefs b/GlassfishFormBasedAuthentication/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..1ab2bb5 --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.jpt.core.prefs b/GlassfishFormBasedAuthentication/.settings/org.eclipse.jpt.core.prefs new file mode 100644 index 0000000..82ac828 --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.jpt.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +org.eclipse.jpt.core.platform=eclipselink2_4 +org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=true diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.component b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..37ff111 --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.component @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..23ae365 --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.project.facet.core.xml b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..69c82de --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.jsdt.ui.superType.container b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.jsdt.ui.superType.name b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.validation.prefs b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..6f1cba6 --- /dev/null +++ b/GlassfishFormBasedAuthentication/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/GlassfishFormBasedAuthentication/README.md b/GlassfishFormBasedAuthentication/README.md new file mode 100644 index 0000000..5e7201f --- /dev/null +++ b/GlassfishFormBasedAuthentication/README.md @@ -0,0 +1,2 @@ +# Source code to Glassfish Form Based Authentication tutorial +Please read the complete tutorial at https://javatutorial.net/glassfish-form-based-authentication-example first. Gslassfish configurations and security setup are described in the tutorial diff --git a/GlassfishFormBasedAuthentication/pom.xml b/GlassfishFormBasedAuthentication/pom.xml new file mode 100644 index 0000000..c14276a --- /dev/null +++ b/GlassfishFormBasedAuthentication/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + net.javatutorial.tutorials + GlassfishFormBasedAuthentication + 1 + war + + + UTF-8 + + + + + javax + javaee-api + 7.0 + provided + + + + + authexample + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + src/main/webapp/WEB-INF/web.xml + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/ejb/UserEJB.java b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/ejb/UserEJB.java new file mode 100644 index 0000000..9e300f6 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/ejb/UserEJB.java @@ -0,0 +1,52 @@ +package net.javatutorial.tutorials.gfauthexample.ejb; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; + +import net.javatutorial.tutorials.gfauthexample.entity.Group; +import net.javatutorial.tutorials.gfauthexample.entity.User; +import net.javatutorial.tutorials.gfauthexample.utils.AuthenticationUtils; + + +@Stateless +public class UserEJB { + + @PersistenceContext(unitName="tutorialsPU") + private EntityManager em; + + public User createUser(User user) { + try { + user.setPassword(AuthenticationUtils.encodeSHA256(user.getPassword())); + } catch (Exception e) { + Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e); + e.printStackTrace(); + } + + Group group = new Group(); + group.setEmail(user.getEmail()); + group.setGroupname(Group.USERS_GROUP); + + em.persist(user); + em.persist(group); + + return user; + } + + public User findUserById(String id) { + TypedQuery query = em.createNamedQuery("findUserById", User.class); + query.setParameter("email", id); + User user = null; + try { + user = query.getSingleResult(); + } catch (Exception e) { + // getSingleResult throws NoResultException in case there is no user in DB + // ignore exception and return NULL for user instead + } + return user; + } +} diff --git a/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/entity/Group.java b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/entity/Group.java new file mode 100644 index 0000000..cde38b6 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/entity/Group.java @@ -0,0 +1,48 @@ +package net.javatutorial.tutorials.gfauthexample.entity; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="user_groups") +public class Group implements Serializable { + + private static final long serialVersionUID = 1528447384986169065L; + + public static final String USERS_GROUP = "users"; + + @Id + @Column(name="email", nullable=false, length=255) + private String email; + + @Column(name="groupname", nullable=false, length=32) + private String groupname; + + public Group() {} + + public Group(String email, String groupname) { + this.email = email; + this.groupname = groupname; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getGroupname() { + return groupname; + } + + public void setGroupname(String groupname) { + this.groupname = groupname; + } + +} diff --git a/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/entity/User.java b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/entity/User.java new file mode 100644 index 0000000..5c9dc86 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/entity/User.java @@ -0,0 +1,62 @@ +package net.javatutorial.tutorials.gfauthexample.entity; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; + +@Entity +@NamedQueries({ + @NamedQuery(name = "findUserById", query = "SELECT u FROM User u WHERE u.email = :email") +}) +@Table(name="users") +public class User implements Serializable { + + private static final long serialVersionUID = -5892169641074303723L; + + @Id + @Column(name="email", nullable=false, length=255) + private String email; + + @Column(name="password", nullable=false, length=64) + private String password; + + @Column(name="name", nullable=false, length=30) + private String name; + + public User(){} + + public User(String email, String password, String name) { + this.email = email; + this.password = password; + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/managedbeans/LoginView.java b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/managedbeans/LoginView.java new file mode 100644 index 0000000..6a281b1 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/managedbeans/LoginView.java @@ -0,0 +1,101 @@ +package net.javatutorial.tutorials.gfauthexample.managedbeans; + +import java.io.Serializable; +import java.security.Principal; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.faces.application.FacesMessage; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import net.javatutorial.tutorials.gfauthexample.ejb.UserEJB; +import net.javatutorial.tutorials.gfauthexample.entity.User; + +@ManagedBean +@SessionScoped +public class LoginView implements Serializable { + + private static final long serialVersionUID = 3254181235309041386L; + + private static Logger log = Logger.getLogger(LoginView.class.getName()); + + @Inject + private UserEJB userEJB; + + private String email; + private String password; + + private User user; + + public String login() { + FacesContext context = FacesContext.getCurrentInstance(); + HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); + + try { + request.login(email, password); + } catch (ServletException e) { + context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Login failed!", null)); + return "signin"; + } + + Principal principal = request.getUserPrincipal(); + + this.user = userEJB.findUserById(principal.getName()); + + log.info("Authentication done for user: " + principal.getName()); + + ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); + Map sessionMap = externalContext.getSessionMap(); + sessionMap.put("User", user); + + if (request.isUserInRole("users")) { + return "/user/privatepage?faces-redirect=true"; + } else { + return "signin"; + } + } + + public String logout() { + FacesContext context = FacesContext.getCurrentInstance(); + HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); + + try { + this.user = null; + request.logout(); + // clear the session + ((HttpSession) context.getExternalContext().getSession(false)).invalidate(); + } catch (ServletException e) { + log.log(Level.SEVERE, "Failed to logout user!", e); + } + + return "/signin?faces-redirect=true"; + } + + public User getAuthenticatedUser() { + return user; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/managedbeans/RegisterView.java b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/managedbeans/RegisterView.java new file mode 100644 index 0000000..5b9cdf2 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/managedbeans/RegisterView.java @@ -0,0 +1,109 @@ +package net.javatutorial.tutorials.gfauthexample.managedbeans; + +import java.io.Serializable; +import java.util.logging.Logger; + +import javax.faces.application.FacesMessage; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.component.UIComponent; +import javax.faces.component.UIInput; +import javax.faces.context.FacesContext; +import javax.faces.event.ComponentSystemEvent; +import javax.inject.Inject; + +import net.javatutorial.tutorials.gfauthexample.ejb.UserEJB; +import net.javatutorial.tutorials.gfauthexample.entity.User; + +@ManagedBean +@SessionScoped +public class RegisterView implements Serializable { + + private static final long serialVersionUID = 1685823449195612778L; + + private static Logger log = Logger.getLogger(RegisterView.class.getName()); + + @Inject + private UserEJB userEJB; + + private String name; + private String email; + private String password; + private String confirmPassword; + + public void validatePassword(ComponentSystemEvent event) { + + FacesContext facesContext = FacesContext.getCurrentInstance(); + + UIComponent components = event.getComponent(); + + // get password + UIInput uiInputPassword = (UIInput) components.findComponent("password"); + String password = uiInputPassword.getLocalValue() == null ? "" : uiInputPassword.getLocalValue().toString(); + String passwordId = uiInputPassword.getClientId(); + + // get confirm password + UIInput uiInputConfirmPassword = (UIInput) components.findComponent("confirmpassword"); + String confirmPassword = uiInputConfirmPassword.getLocalValue() == null ? "" + : uiInputConfirmPassword.getLocalValue().toString(); + + // Let required="true" do its job. + if (password.isEmpty() || confirmPassword.isEmpty()) { + return; + } + + if (!password.equals(confirmPassword)) { + FacesMessage msg = new FacesMessage("Confirm password does not match password"); + msg.setSeverity(FacesMessage.SEVERITY_ERROR); + facesContext.addMessage(passwordId, msg); + facesContext.renderResponse(); + } + + if (userEJB.findUserById(email) != null) { + FacesMessage msg = new FacesMessage("User with this e-mail already exists"); + msg.setSeverity(FacesMessage.SEVERITY_ERROR); + facesContext.addMessage(passwordId, msg); + facesContext.renderResponse(); + } + + } + + public String register() { + User user = new User(email, password, name); + userEJB.createUser(user); + log.info("New user created with e-mail: " + email + " and name: " + name); + return "regdone"; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getConfirmPassword() { + return confirmPassword; + } + + public void setConfirmPassword(String confirmPassword) { + this.confirmPassword = confirmPassword; + } +} diff --git a/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/utils/AuthenticationUtils.java b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/utils/AuthenticationUtils.java new file mode 100644 index 0000000..1ba2d11 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/utils/AuthenticationUtils.java @@ -0,0 +1,26 @@ +package net.javatutorial.tutorials.gfauthexample.utils; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import javax.xml.bind.DatatypeConverter; + +public final class AuthenticationUtils { + + /** + * Returns SHA-256 encoded string + * @param password - the string to be encoded + * @return SHA-256 encoded string + * @throws UnsupportedEncodingException if UTF-8 is not supported by the system + * @throws NoSuchAlgorithmException if SHA-256 is not supported by the system + */ + public static String encodeSHA256(String password) + throws UnsupportedEncodingException, NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + md.update(password.getBytes("UTF-8")); + byte[] digest = md.digest(); + return DatatypeConverter.printBase64Binary(digest).toString(); + } + +} diff --git a/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/validators/EmailValidator.java b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/validators/EmailValidator.java new file mode 100644 index 0000000..26c4cf3 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/java/net/javatutorial/tutorials/gfauthexample/validators/EmailValidator.java @@ -0,0 +1,35 @@ +package net.javatutorial.tutorials.gfauthexample.validators; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.FacesValidator; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; + +@FacesValidator("emailValidator") +public class EmailValidator implements Validator { + + private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\." + + "[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*" + + "(\\.[A-Za-z]{2,})$"; + + private Pattern pattern; + private Matcher matcher; + + public EmailValidator(){ + pattern = Pattern.compile(EMAIL_PATTERN); + } + + @Override + public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { + matcher = pattern.matcher(value.toString()); + if(!matcher.matches()){ + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid e-mail address", null)); + } + } + +} diff --git a/GlassfishFormBasedAuthentication/src/main/resources/META-INF/persistence.xml b/GlassfishFormBasedAuthentication/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..5e7ae5f --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,28 @@ + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + jdbc/tutorialsDS + net.javatutorial.tutorials.gfauthexample.entity.User + net.javatutorial.tutorials.gfauthexample.entity.Group + + + + + + + + + + + \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/src/main/webapp/WEB-INF/glassfish-web.xml b/GlassfishFormBasedAuthentication/src/main/webapp/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..b2fb3cc --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/webapp/WEB-INF/glassfish-web.xml @@ -0,0 +1,15 @@ + + + + + users + users + + + + + Keep a copy of the generated servlet class' java code. + + + + \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/src/main/webapp/WEB-INF/web.xml b/GlassfishFormBasedAuthentication/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..619aa6b --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,66 @@ + + + + Form Based Auth Example + + + javax.faces.PROJECT_STAGE + Development + + + javax.faces.DEFAULT_SUFFIX + .xhtml + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + + Faces Servlet + *.xhtml + + + + + 300 + + + + + signin.xhtml + + + + + FORM + jdbc-realm + + /signin.xhtml + /signin.xhtml + + + + + + users + + + + Restricted to users + + Restricted Access + /user/* + + + users + + + NONE + + + \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/src/main/webapp/regdone.xhtml b/GlassfishFormBasedAuthentication/src/main/webapp/regdone.xhtml new file mode 100644 index 0000000..46ed23e --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/webapp/regdone.xhtml @@ -0,0 +1,12 @@ + + + + Registration done + + +

Your account has been successfully created

+

+ +
+ \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/src/main/webapp/register.xhtml b/GlassfishFormBasedAuthentication/src/main/webapp/register.xhtml new file mode 100644 index 0000000..2360759 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/webapp/register.xhtml @@ -0,0 +1,43 @@ + + + + register + + + + + + + + +

Create new account

+ + Name: + + + E-Mail: + + + + + Password: + + + + + Confirm password: + + + + + + +
+ +

+ + +
+ \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/src/main/webapp/signin.xhtml b/GlassfishFormBasedAuthentication/src/main/webapp/signin.xhtml new file mode 100644 index 0000000..4d61859 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/webapp/signin.xhtml @@ -0,0 +1,26 @@ + + + + login + + + + +

Please Sign In

+ + E-Mail: + + + Password: + + + + +
+ +

+ + +
+ \ No newline at end of file diff --git a/GlassfishFormBasedAuthentication/src/main/webapp/user/privatepage.xhtml b/GlassfishFormBasedAuthentication/src/main/webapp/user/privatepage.xhtml new file mode 100644 index 0000000..f9bdb35 --- /dev/null +++ b/GlassfishFormBasedAuthentication/src/main/webapp/user/privatepage.xhtml @@ -0,0 +1,15 @@ + + + + Private Page + + + + + +

Hello #{loginView.authenticatedUser.name}

+

Your user id is #{loginView.authenticatedUser.email}

+

This is a private page, which requires login to access.

+
+ \ No newline at end of file diff --git a/GridViewExample.rar b/GridViewExample.rar new file mode 100644 index 0000000..397345c Binary files /dev/null and b/GridViewExample.rar differ diff --git a/IntentExample.rar b/IntentExample.rar new file mode 100644 index 0000000..e703b3f Binary files /dev/null and b/IntentExample.rar differ diff --git a/JSPExample/README.md b/JSPExample/README.md new file mode 100644 index 0000000..ca97df0 --- /dev/null +++ b/JSPExample/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/java-jsp-example diff --git a/JSPExample/pom.xml b/JSPExample/pom.xml new file mode 100644 index 0000000..9f03b74 --- /dev/null +++ b/JSPExample/pom.xml @@ -0,0 +1,54 @@ + + 4.0.0 + + net.javatutorial.tutorials + JSPExample + 1 + war + + JSPExample + https://javatutorial.net + + + UTF-8 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + javax.servlet.jsp + javax.servlet.jsp-api + 2.3.1 + provided + + + + + jspexample + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + src/main/webapp + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/JSPExample/src/main/webapp/WEB-INF/web.xml b/JSPExample/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..442b7ce --- /dev/null +++ b/JSPExample/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,4 @@ + + + JSP Example + \ No newline at end of file diff --git a/JSPExample/src/main/webapp/index.jsp b/JSPExample/src/main/webapp/index.jsp new file mode 100644 index 0000000..b8fcd67 --- /dev/null +++ b/JSPExample/src/main/webapp/index.jsp @@ -0,0 +1,12 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ page import="java.time.LocalDateTime" %> + + + + Simple JSP Application + + +

Hello world!

+

Current time is <%= LocalDateTime.now() %>

+ + \ No newline at end of file diff --git a/JSPExample/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/JSPExample/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..fd779cd --- /dev/null +++ b/JSPExample/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: filip +Build-Jdk: 1.8.0_73 +Created-By: Maven Integration for Eclipse + diff --git a/JSPExample/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/JSPExample/pom.properties b/JSPExample/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/JSPExample/pom.properties new file mode 100644 index 0000000..0b3efd8 --- /dev/null +++ b/JSPExample/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/JSPExample/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Fri Nov 24 15:44:46 EET 2017 +version=1 +groupId=net.javatutorial.tutorials +m2e.projectName=JSPExample +m2e.projectLocation=/Users/filip/Development/GitHub/JavaTutorialNet/JSPExample +artifactId=JSPExample diff --git a/JSPExample/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/JSPExample/pom.xml b/JSPExample/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/JSPExample/pom.xml new file mode 100644 index 0000000..9f03b74 --- /dev/null +++ b/JSPExample/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/JSPExample/pom.xml @@ -0,0 +1,54 @@ + + 4.0.0 + + net.javatutorial.tutorials + JSPExample + 1 + war + + JSPExample + https://javatutorial.net + + + UTF-8 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + javax.servlet.jsp + javax.servlet.jsp-api + 2.3.1 + provided + + + + + jspexample + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + src/main/webapp + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/LinearLayoutExample.rar b/LinearLayoutExample.rar new file mode 100644 index 0000000..992fab0 Binary files /dev/null and b/LinearLayoutExample.rar differ diff --git a/ListAdapterExample.rar b/ListAdapterExample.rar new file mode 100644 index 0000000..8926f00 Binary files /dev/null and b/ListAdapterExample.rar differ diff --git a/ListViewExample.rar b/ListViewExample.rar new file mode 100644 index 0000000..31e4e49 Binary files /dev/null and b/ListViewExample.rar differ diff --git a/README.md b/README.md index 395befe..89cf356 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # Tutorials -Source code for tutorials listed on javatutorial.net + +Hi there and welcome to the GitHub repository of [Java Tutorial Network](https://javatutorial.net). Here you will find the source codes of the examples posted on the site. + +Please note: Java is a great and vast programming language and you should strive to write your code in the best way you can, using comments, proper exception handling, object oriented principles and design patterns. Having said this, the examples on https://javatutorial.net and the code you will find here are not always perfect. You may find short codes, with missing exception handling. Please have in mind, we do this on purpose. As strange this may sound, we try to keep the examples short and easy to follow and sometimes sacrifice the exception handling and other object oriented principles. + +You can use the code in this repository to complete all your development tasks - no matter if you are writing a open-source project or a commercial software. I believe knowledge is not a privilege and should be shared without affording payment for it. Use the code as you like. + +I will be happy if you spread the word and post a link to javatutorial.net in your projects, so other people can also benefit from free knowledge. + +Thank you! diff --git a/RaspberryPiControlMotors/.classpath b/RaspberryPiControlMotors/.classpath new file mode 100644 index 0000000..60ee054 --- /dev/null +++ b/RaspberryPiControlMotors/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/RaspberryPiControlMotors/.gitignore b/RaspberryPiControlMotors/.gitignore new file mode 100644 index 0000000..fd7710a --- /dev/null +++ b/RaspberryPiControlMotors/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/.DS_Store diff --git a/RaspberryPiControlMotors/.project b/RaspberryPiControlMotors/.project new file mode 100644 index 0000000..fb3fce6 --- /dev/null +++ b/RaspberryPiControlMotors/.project @@ -0,0 +1,17 @@ + + + RaspberryPiControlMotors + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/RaspberryPiControlMotors/.settings/org.eclipse.jdt.core.prefs b/RaspberryPiControlMotors/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bb35fa0 --- /dev/null +++ b/RaspberryPiControlMotors/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/RaspberryPiControlMotors/README.md b/RaspberryPiControlMotors/README.md new file mode 100644 index 0000000..a5b70ba --- /dev/null +++ b/RaspberryPiControlMotors/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/raspberry-pi-control-dc-motor-speed-and-direction-java diff --git a/RaspberryPiControlMotors/lib/junit.jar b/RaspberryPiControlMotors/lib/junit.jar new file mode 100644 index 0000000..aaf7444 Binary files /dev/null and b/RaspberryPiControlMotors/lib/junit.jar differ diff --git a/RaspberryPiControlMotors/lib/pi4j-core.jar b/RaspberryPiControlMotors/lib/pi4j-core.jar new file mode 100644 index 0000000..021a6c7 Binary files /dev/null and b/RaspberryPiControlMotors/lib/pi4j-core.jar differ diff --git a/RaspberryPiControlMotors/lib/pi4j-device.jar b/RaspberryPiControlMotors/lib/pi4j-device.jar new file mode 100644 index 0000000..9bd9690 Binary files /dev/null and b/RaspberryPiControlMotors/lib/pi4j-device.jar differ diff --git a/RaspberryPiControlMotors/lib/pi4j-gpio-extension.jar b/RaspberryPiControlMotors/lib/pi4j-gpio-extension.jar new file mode 100644 index 0000000..32a3cbc Binary files /dev/null and b/RaspberryPiControlMotors/lib/pi4j-gpio-extension.jar differ diff --git a/RaspberryPiControlMotors/lib/pi4j-service.jar b/RaspberryPiControlMotors/lib/pi4j-service.jar new file mode 100644 index 0000000..9e19f0c Binary files /dev/null and b/RaspberryPiControlMotors/lib/pi4j-service.jar differ diff --git a/RaspberryPiControlMotors/src/ControlMotorsDirectionAndSpeed.java b/RaspberryPiControlMotors/src/ControlMotorsDirectionAndSpeed.java new file mode 100644 index 0000000..b064003 --- /dev/null +++ b/RaspberryPiControlMotors/src/ControlMotorsDirectionAndSpeed.java @@ -0,0 +1,84 @@ +import com.pi4j.io.gpio.GpioController; +import com.pi4j.io.gpio.GpioFactory; +import com.pi4j.io.gpio.GpioPinDigitalOutput; +import com.pi4j.io.gpio.RaspiPin; +import com.pi4j.wiringpi.SoftPwm; + +/** + * Controls motor speed and direction of two DC motors + * @author https://javatutorial.net + */ +public class ControlMotorsDirectionAndSpeed { + + private static int MOTOR_1_PIN_A = 4; + private static int MOTOR_1_PIN_B = 5; + private static int MOTOR_2_PIN_A = 0; + private static int MOTOR_2_PIN_B = 2; + + public static void main(String[] args) throws InterruptedException { + // get a handle to the GPIO controller + final GpioController gpio = GpioFactory.getInstance(); + + // init soft PWM pins + // softPwmCreate(int pin, int value, int range) + // the range is set like (min=0 ; max=100) + SoftPwm.softPwmCreate(MOTOR_1_PIN_A, 0, 100); + SoftPwm.softPwmCreate(MOTOR_1_PIN_B, 0, 100); + SoftPwm.softPwmCreate(MOTOR_2_PIN_A, 0, 100); + SoftPwm.softPwmCreate(MOTOR_2_PIN_B, 0, 100); + + // init GPIO pins + final GpioPinDigitalOutput motor1pinE = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, "m1E"); + final GpioPinDigitalOutput motor2pinE = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, "m2E"); + + System.out.println("rotate motor 1 clockwise at 15% speed for 2 seconds"); + motor1pinE.high(); + SoftPwm.softPwmWrite(MOTOR_1_PIN_A, 15); + + // wait 2 seconds + Thread.sleep(2000); + + System.out.println("rotate motor 1 clockwise at 60% speed for 2 seconds"); + SoftPwm.softPwmWrite(MOTOR_1_PIN_A, 60); + + // wait 2 seconds + Thread.sleep(2000); + + System.out.println("rotate motor 1 clockwise at full speed for 2 seconds"); + SoftPwm.softPwmWrite(MOTOR_1_PIN_A, 100); + + // wait 2 seconds + Thread.sleep(2000); + + System.out.println("rotate motor 1 in oposite direction at 50% speed for 3 seconds"); + SoftPwm.softPwmWrite(MOTOR_1_PIN_A, 0); + SoftPwm.softPwmWrite(MOTOR_1_PIN_B, 50); + + // wait 3 seconds + Thread.sleep(3000); + + // disable motor 1 + SoftPwm.softPwmWrite(MOTOR_1_PIN_B, 0); + motor1pinE.low(); + + System.out.println("rotate motor 2 clockwise at 30% speed for 2 seconds"); + motor2pinE.high(); + SoftPwm.softPwmWrite(MOTOR_2_PIN_A, 30); + + // wait 2 seconds + Thread.sleep(2000); + + System.out.println("rotate motor 2 in oposite direction at 100% speed for 3 seconds"); + SoftPwm.softPwmWrite(MOTOR_2_PIN_A, 0); + SoftPwm.softPwmWrite(MOTOR_2_PIN_B, 100); + + // wait 3 seconds + Thread.sleep(3000); + + // disable motor 2 + SoftPwm.softPwmWrite(MOTOR_2_PIN_B, 0); + motor2pinE.low(); + + gpio.shutdown(); + } +} diff --git a/RaspberryPiControlMotors/src/ControlOneMotorDirection.java b/RaspberryPiControlMotors/src/ControlOneMotorDirection.java new file mode 100644 index 0000000..32667bd --- /dev/null +++ b/RaspberryPiControlMotors/src/ControlOneMotorDirection.java @@ -0,0 +1,41 @@ +import com.pi4j.io.gpio.GpioController; +import com.pi4j.io.gpio.GpioFactory; +import com.pi4j.io.gpio.GpioPinDigitalOutput; +import com.pi4j.io.gpio.RaspiPin; + +/** + * Controls motor direction of a single motor + * @author https://javatutorial.net + */ +public class ControlOneMotorDirection { + + public static void main(String[] args) throws InterruptedException { + // get a handle to the GPIO controller + final GpioController gpio = GpioFactory.getInstance(); + + final GpioPinDigitalOutput pinA = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, "PinA"); + final GpioPinDigitalOutput pinB = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05, "PinB"); + final GpioPinDigitalOutput pinE = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, "PinE"); + + System.out.println("rotate motor clock-wise for 3 seconds"); + pinA.high(); + pinB.low(); + pinE.high(); + + // wait 3 seconds + Thread.sleep(3000); + + System.out.println("rotate motor in oposite derection for 6 seconds"); + pinA.low(); + pinB.high(); + + // wait 6 seconds + Thread.sleep(6000); + + // stop motor + System.out.println("Stopping motor"); + pinE.low(); + + gpio.shutdown(); + } +} diff --git a/RaspberryPiControlMotors/src/ControlTwoMotorsDirection.java b/RaspberryPiControlMotors/src/ControlTwoMotorsDirection.java new file mode 100644 index 0000000..8df8f04 --- /dev/null +++ b/RaspberryPiControlMotors/src/ControlTwoMotorsDirection.java @@ -0,0 +1,53 @@ +import com.pi4j.io.gpio.GpioController; +import com.pi4j.io.gpio.GpioFactory; +import com.pi4j.io.gpio.GpioPinDigitalOutput; +import com.pi4j.io.gpio.RaspiPin; + +/** + * Controls motor direction of a two DC motors + * @author https://javatutorial.net + */ +public class ControlTwoMotorsDirection { + + public static void main(String[] args) throws InterruptedException { + // get a handle to the GPIO controller + final GpioController gpio = GpioFactory.getInstance(); + + final GpioPinDigitalOutput motor1pinA = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, "m1A"); + final GpioPinDigitalOutput motor1pinB = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05, "m1B"); + final GpioPinDigitalOutput motor1pinE = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, "m1E"); + final GpioPinDigitalOutput motor2pinA = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00, "m2A"); + final GpioPinDigitalOutput motor2pinB = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, "m2B"); + final GpioPinDigitalOutput motor2pinE = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, "m2E"); + + System.out.println("rotate both motors clockwise for 3 seconds"); + motor1pinA.high(); + motor1pinB.low(); + motor1pinE.high(); + motor2pinA.high(); + motor2pinB.low(); + motor2pinE.high(); + + // wait 3 seconds + Thread.sleep(3000); + + System.out.println("rotate motor 1 in oposite derection for 3 seconds " + + "and motor 2 in oposite direction for 6 seconds"); + motor1pinA.low(); + motor1pinB.high(); + motor2pinA.low(); + motor2pinB.high(); + + // wait 3 seconds + Thread.sleep(3000); + System.out.println("Stopping motor 1"); + motor1pinE.low(); + + // wait 3 seconds + Thread.sleep(3000); + System.out.println("Stopping motor 2"); + motor2pinE.low(); + + gpio.shutdown(); + } +} diff --git a/RelativeLayout.rar b/RelativeLayout.rar new file mode 100644 index 0000000..aeeb638 Binary files /dev/null and b/RelativeLayout.rar differ diff --git a/ServletAnnotation/.classpath b/ServletAnnotation/.classpath new file mode 100644 index 0000000..6573228 --- /dev/null +++ b/ServletAnnotation/.classpath @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ServletAnnotation/.gitignore b/ServletAnnotation/.gitignore new file mode 100644 index 0000000..e3d2422 --- /dev/null +++ b/ServletAnnotation/.gitignore @@ -0,0 +1,2 @@ +/target/ +/.DS_Store diff --git a/ServletAnnotation/.project b/ServletAnnotation/.project new file mode 100644 index 0000000..05633ec --- /dev/null +++ b/ServletAnnotation/.project @@ -0,0 +1,42 @@ + + + ServletAnnotation + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/ServletAnnotation/.settings/.jsdtscope b/ServletAnnotation/.settings/.jsdtscope new file mode 100644 index 0000000..4c76941 --- /dev/null +++ b/ServletAnnotation/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/ServletAnnotation/.settings/org.eclipse.core.resources.prefs b/ServletAnnotation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..4c28b1a --- /dev/null +++ b/ServletAnnotation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/ServletAnnotation/.settings/org.eclipse.jdt.core.prefs b/ServletAnnotation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..1ab2bb5 --- /dev/null +++ b/ServletAnnotation/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ServletAnnotation/.settings/org.eclipse.m2e.core.prefs b/ServletAnnotation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..14b697b --- /dev/null +++ b/ServletAnnotation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/ServletAnnotation/.settings/org.eclipse.wst.common.component b/ServletAnnotation/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..626dc3b --- /dev/null +++ b/ServletAnnotation/.settings/org.eclipse.wst.common.component @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/ServletAnnotation/.settings/org.eclipse.wst.common.project.facet.core.xml b/ServletAnnotation/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..888ec46 --- /dev/null +++ b/ServletAnnotation/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ServletAnnotation/.settings/org.eclipse.wst.jsdt.ui.superType.container b/ServletAnnotation/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/ServletAnnotation/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/ServletAnnotation/.settings/org.eclipse.wst.jsdt.ui.superType.name b/ServletAnnotation/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/ServletAnnotation/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/ServletAnnotation/.settings/org.eclipse.wst.validation.prefs b/ServletAnnotation/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..6f1cba6 --- /dev/null +++ b/ServletAnnotation/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/ServletAnnotation/README.md b/ServletAnnotation/README.md new file mode 100644 index 0000000..366974b --- /dev/null +++ b/ServletAnnotation/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/servlet-annotation-example diff --git a/ServletAnnotation/pom.xml b/ServletAnnotation/pom.xml new file mode 100644 index 0000000..7524745 --- /dev/null +++ b/ServletAnnotation/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + + net.javatutorial.tutorials + ServletAnnotation + 1 + war + + ServletAnnotation + https://javatutorial.net + + + UTF-8 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + + servletannotation + src/main/java + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + src/main/webapp + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + diff --git a/ServletAnnotation/src/.DS_Store b/ServletAnnotation/src/.DS_Store new file mode 100644 index 0000000..c3e1038 Binary files /dev/null and b/ServletAnnotation/src/.DS_Store differ diff --git a/ServletAnnotation/src/main/.DS_Store b/ServletAnnotation/src/main/.DS_Store new file mode 100644 index 0000000..9761ca5 Binary files /dev/null and b/ServletAnnotation/src/main/.DS_Store differ diff --git a/ServletAnnotation/src/main/java/.DS_Store b/ServletAnnotation/src/main/java/.DS_Store new file mode 100644 index 0000000..3f94f28 Binary files /dev/null and b/ServletAnnotation/src/main/java/.DS_Store differ diff --git a/ServletAnnotation/src/main/java/net/.DS_Store b/ServletAnnotation/src/main/java/net/.DS_Store new file mode 100644 index 0000000..302ab72 Binary files /dev/null and b/ServletAnnotation/src/main/java/net/.DS_Store differ diff --git a/ServletAnnotation/src/main/java/net/javatutorial/.DS_Store b/ServletAnnotation/src/main/java/net/javatutorial/.DS_Store new file mode 100644 index 0000000..8a20303 Binary files /dev/null and b/ServletAnnotation/src/main/java/net/javatutorial/.DS_Store differ diff --git a/ServletAnnotation/src/main/java/net/javatutorial/tutorials/ServletWithAnnotations.java b/ServletAnnotation/src/main/java/net/javatutorial/tutorials/ServletWithAnnotations.java new file mode 100644 index 0000000..5573d85 --- /dev/null +++ b/ServletAnnotation/src/main/java/net/javatutorial/tutorials/ServletWithAnnotations.java @@ -0,0 +1,22 @@ +package net.javatutorial.tutorials; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name = "simpleServlet", urlPatterns = { "/hello" }, loadOnStartup = 1) +public class ServletWithAnnotations extends HttpServlet { + + private static final long serialVersionUID = -3462096228274971485L; + + @Override + protected void doGet(HttpServletRequest reqest, HttpServletResponse response) + throws ServletException, IOException { + response.getWriter().println("Hello World!"); + } + +} diff --git a/ServletAnnotation/src/main/webapp/.DS_Store b/ServletAnnotation/src/main/webapp/.DS_Store new file mode 100644 index 0000000..b9d7414 Binary files /dev/null and b/ServletAnnotation/src/main/webapp/.DS_Store differ diff --git a/ServletAnnotation/src/main/webapp/WEB-INF/web.xml b/ServletAnnotation/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..db52a37 --- /dev/null +++ b/ServletAnnotation/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,9 @@ + + + + + Servlet with Annotations Application + + \ No newline at end of file diff --git a/ServletFileUpload/README.md b/ServletFileUpload/README.md new file mode 100644 index 0000000..b94b2b4 --- /dev/null +++ b/ServletFileUpload/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/java-servlet-file-upload diff --git a/ServletFileUpload/pom.xml b/ServletFileUpload/pom.xml new file mode 100644 index 0000000..00d80b6 --- /dev/null +++ b/ServletFileUpload/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + + net.javatutorial.tutorials + ServletFileUpload + 1 + war + + ServletFileUpload + https://javatutorial.net + + + UTF-8 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + + fileuploader + src/main/java + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + src/main/webapp + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + diff --git a/ServletFileUpload/src/main/java/net/javatutorial/tutorials/FileUploadServlet.java b/ServletFileUpload/src/main/java/net/javatutorial/tutorials/FileUploadServlet.java new file mode 100644 index 0000000..6b9706e --- /dev/null +++ b/ServletFileUpload/src/main/java/net/javatutorial/tutorials/FileUploadServlet.java @@ -0,0 +1,94 @@ +package net.javatutorial.tutorials; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.Part; + +@WebServlet(name = "uploadServlet", urlPatterns = { "/upload" }, loadOnStartup = 1) +@MultipartConfig(fileSizeThreshold = 6291456, // 6 MB + maxFileSize = 10485760L, // 10 MB + maxRequestSize = 20971520L // 20 MB +) +public class FileUploadServlet extends HttpServlet { + + private static final long serialVersionUID = 5619951677845873534L; + + private static final String UPLOAD_DIR = "uploads"; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + + PrintWriter writer = response.getWriter(); + writer.append("\r\n") + .append("\r\n") + .append(" \r\n") + .append(" File Upload Form\r\n") + .append(" \r\n") + .append(" \r\n"); + + writer.append("

Upload file

\r\n"); + writer.append("
\r\n"); + writer.append("

\r\n"); + writer.append("

\r\n"); + writer.append("\r\n"); + writer.append("
\r\n"); + + writer.append(" \r\n").append("\r\n"); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + + // gets absolute path of the web application + String applicationPath = request.getServletContext().getRealPath(""); + // constructs path of the directory to save uploaded file + String uploadFilePath = applicationPath + File.separator + UPLOAD_DIR; + + // creates upload folder if it does not exists + File uploadFolder = new File(uploadFilePath); + if (!uploadFolder.exists()) { + uploadFolder.mkdirs(); + } + + PrintWriter writer = response.getWriter(); + + // write all files in upload folder + for (Part part : request.getParts()) { + if (part != null && part.getSize() > 0) { + String fileName = part.getSubmittedFileName(); + String contentType = part.getContentType(); + + // allows only JPEG files to be uploaded + if (!contentType.equalsIgnoreCase("image/jpeg")) { + continue; + } + + part.write(uploadFilePath + File.separator + fileName); + + writer.append("File successfully uploaded to " + + uploadFolder.getAbsolutePath() + + File.separator + + fileName + + "
\r\n"); + } + } + + } + +} diff --git a/ServletFileUpload/src/main/webapp/WEB-INF/web.xml b/ServletFileUpload/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..61c8038 --- /dev/null +++ b/ServletFileUpload/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,9 @@ + + + + + File Upload Servelet Example + + \ No newline at end of file diff --git a/ServletFileUpload/target/classes/net/javatutorial/tutorials/FileUploadServlet.class b/ServletFileUpload/target/classes/net/javatutorial/tutorials/FileUploadServlet.class new file mode 100644 index 0000000..c21a315 Binary files /dev/null and b/ServletFileUpload/target/classes/net/javatutorial/tutorials/FileUploadServlet.class differ diff --git a/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..fd779cd --- /dev/null +++ b/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: filip +Build-Jdk: 1.8.0_73 +Created-By: Maven Integration for Eclipse + diff --git a/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/ServletFileUpload/pom.properties b/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/ServletFileUpload/pom.properties new file mode 100644 index 0000000..1e7f0e2 --- /dev/null +++ b/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/ServletFileUpload/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Sat Nov 18 18:45:33 EET 2017 +version=1 +groupId=net.javatutorial.tutorials +m2e.projectName=ServletFileUpload +m2e.projectLocation=/Users/filip/Development/GitHub/JavaTutorialNet/ServletFileUpload +artifactId=ServletFileUpload diff --git a/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/ServletFileUpload/pom.xml b/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/ServletFileUpload/pom.xml new file mode 100644 index 0000000..00d80b6 --- /dev/null +++ b/ServletFileUpload/target/m2e-wtp/web-resources/META-INF/maven/net.javatutorial.tutorials/ServletFileUpload/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + + net.javatutorial.tutorials + ServletFileUpload + 1 + war + + ServletFileUpload + https://javatutorial.net + + + UTF-8 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + + fileuploader + src/main/java + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + src/main/webapp + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + diff --git a/ServletInfo/README.md b/ServletInfo/README.md new file mode 100644 index 0000000..392c7a1 --- /dev/null +++ b/ServletInfo/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/servlet-request-info-example diff --git a/ServletPOSTExample/.classpath b/ServletPOSTExample/.classpath new file mode 100644 index 0000000..892b0d6 --- /dev/null +++ b/ServletPOSTExample/.classpath @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ServletPOSTExample/.gitignore b/ServletPOSTExample/.gitignore new file mode 100644 index 0000000..d274d47 --- /dev/null +++ b/ServletPOSTExample/.gitignore @@ -0,0 +1,3 @@ +/target/ +/.settings/ +/.DS_Store diff --git a/ServletPOSTExample/.project b/ServletPOSTExample/.project new file mode 100644 index 0000000..e2b70cd --- /dev/null +++ b/ServletPOSTExample/.project @@ -0,0 +1,42 @@ + + + ServletPOSTExample + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/ServletPOSTExample/README.md b/ServletPOSTExample/README.md new file mode 100644 index 0000000..3a4dc70 --- /dev/null +++ b/ServletPOSTExample/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/java-servlet-post-example diff --git a/ServletPOSTExample/pom.xml b/ServletPOSTExample/pom.xml new file mode 100644 index 0000000..01e6c79 --- /dev/null +++ b/ServletPOSTExample/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + + net.javatutorial.tutorials + ServletPOSTExample + 1 + war + + Servlet POST Example + https://javatutorial.net + + + UTF-8 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + + servletpost + src/main/java + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + src/main/webapp + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + diff --git a/ServletPOSTExample/src/main/java/net/javatutorial/tutorials/ServletPOST.java b/ServletPOSTExample/src/main/java/net/javatutorial/tutorials/ServletPOST.java new file mode 100644 index 0000000..a548a3e --- /dev/null +++ b/ServletPOSTExample/src/main/java/net/javatutorial/tutorials/ServletPOST.java @@ -0,0 +1,66 @@ +package net.javatutorial.tutorials; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ServletPOST extends HttpServlet { + + private static final long serialVersionUID = -1641096228274971485L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + // set response headers + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + + // create HTML form + PrintWriter writer = response.getWriter(); + writer.append("\r\n") + .append("\r\n") + .append(" \r\n") + .append(" Form input\r\n") + .append(" \r\n") + .append(" \r\n") + .append("
\r\n") + .append(" Enter your name: \r\n") + .append(" \r\n") + .append(" \r\n") + .append("
\r\n") + .append(" \r\n") + .append("\r\n"); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String user = request.getParameter("user"); + + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + + // create HTML response + PrintWriter writer = response.getWriter(); + writer.append("\r\n") + .append("\r\n") + .append(" \r\n") + .append(" Welcome message\r\n") + .append(" \r\n") + .append(" \r\n"); + if (user != null && !user.trim().isEmpty()) { + writer.append(" Welcome " + user + ".\r\n"); + writer.append(" You successfully completed this javatutorial.net example.\r\n"); + } else { + writer.append(" You did not entered a name!\r\n"); + } + writer.append(" \r\n") + .append("\r\n"); + } + +} diff --git a/ServletPOSTExample/src/main/webapp/WEB-INF/web.xml b/ServletPOSTExample/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..f8a5b22 --- /dev/null +++ b/ServletPOSTExample/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + + + Simple Servlet Application + + + servletPost + net.javatutorial.tutorials.ServletPOST + 1 + + + + servletPost + /welcome + + + \ No newline at end of file diff --git a/SimpleAndroidApp.rar b/SimpleAndroidApp.rar new file mode 100644 index 0000000..be18485 Binary files /dev/null and b/SimpleAndroidApp.rar differ diff --git a/SimpleServlet/README.md b/SimpleServlet/README.md new file mode 100644 index 0000000..9bcd9ca --- /dev/null +++ b/SimpleServlet/README.md @@ -0,0 +1,9 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/java-servlet-example + +# Build using command line +- Install JDK, Maven +- git clone https://github.com/JavaTutorialNetwork/Tutorials.git +- cd Tutorials/SimpleServlet +- mvn clean +- mvn package +| the war file will be built in target/SimpleServlet-1.war diff --git a/SpringBootExample/README.md b/SpringBootExample/README.md new file mode 100644 index 0000000..1b82ab3 --- /dev/null +++ b/SpringBootExample/README.md @@ -0,0 +1 @@ +For code explanation and additional configurations read the tutorial at https://javatutorial.net/spring-web-app-sts diff --git a/SpringBootExample/mvnw b/SpringBootExample/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/SpringBootExample/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/SpringBootExample/mvnw.cmd b/SpringBootExample/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/SpringBootExample/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/SpringBootExample/pom.xml b/SpringBootExample/pom.xml new file mode 100644 index 0000000..964173b --- /dev/null +++ b/SpringBootExample/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + net.javavatutorial + springexample + 1 + jar + + SpringBootExample + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 1.5.8.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/SpringBootExample/src/main/java/net/javavatutorial/tutorials/SpringBootExampleApplication.java b/SpringBootExample/src/main/java/net/javavatutorial/tutorials/SpringBootExampleApplication.java new file mode 100644 index 0000000..913871f --- /dev/null +++ b/SpringBootExample/src/main/java/net/javavatutorial/tutorials/SpringBootExampleApplication.java @@ -0,0 +1,22 @@ +package net.javavatutorial.tutorials; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@SpringBootApplication +public class SpringBootExampleApplication { + + @RequestMapping("/") + @ResponseBody + String home() { + return "Greetings from Java Tutorial Network"; + } + + public static void main(String[] args) { + SpringApplication.run(SpringBootExampleApplication.class, args); + } +} diff --git a/SpringBootExample/src/test/java/net/javavatutorial/tutorials/SpringBootExampleApplicationTests.java b/SpringBootExample/src/test/java/net/javavatutorial/tutorials/SpringBootExampleApplicationTests.java new file mode 100644 index 0000000..114db98 --- /dev/null +++ b/SpringBootExample/src/test/java/net/javavatutorial/tutorials/SpringBootExampleApplicationTests.java @@ -0,0 +1,16 @@ +package net.javavatutorial.tutorials; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringBootExampleApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/SpringImplementingControllers/mvnw b/SpringImplementingControllers/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/SpringImplementingControllers/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/SpringImplementingControllers/mvnw.cmd b/SpringImplementingControllers/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/SpringImplementingControllers/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/SpringImplementingControllers/pom.xml b/SpringImplementingControllers/pom.xml new file mode 100644 index 0000000..5e8bbef --- /dev/null +++ b/SpringImplementingControllers/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + net.javavatutorial + SpringImplementingControllers + 1 + jar + + SpringImplementingControllers + Demo project for Spring MVC Controller Implementation + + + org.springframework.boot + spring-boot-starter-parent + 1.5.9.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.apache.tomcat.embed + tomcat-embed-jasper + + + + javax.servlet + jstl + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/ControllerExampleJSP.java b/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/ControllerExampleJSP.java new file mode 100644 index 0000000..563d7a8 --- /dev/null +++ b/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/ControllerExampleJSP.java @@ -0,0 +1,20 @@ +package net.javavatutorial.tutorials; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@SpringBootApplication +public class ControllerExampleJSP { + + @RequestMapping("/hellojsp") + String helloJSP() { + return("index"); + } + + public static void main(String[] args) { + SpringApplication.run(ControllerExampleJSP.class, args); + } +} diff --git a/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/ControllerResponseBodyExample.java b/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/ControllerResponseBodyExample.java new file mode 100644 index 0000000..30ea055 --- /dev/null +++ b/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/ControllerResponseBodyExample.java @@ -0,0 +1,24 @@ +package net.javavatutorial.tutorials; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + + +@Controller +@SpringBootApplication +public class ControllerResponseBodyExample { + + @RequestMapping("/helloresponsebody") + @ResponseBody + String helloResponseBody() { + return("Hello World. This is produced by a method annotated with ResponseBody"); + } + + public static void main(String[] args) { + SpringApplication.run(ControllerResponseBodyExample.class, args); + } + +} \ No newline at end of file diff --git a/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/MethodAndClassLevelAnnotations.java b/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/MethodAndClassLevelAnnotations.java new file mode 100644 index 0000000..ce8c696 --- /dev/null +++ b/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/MethodAndClassLevelAnnotations.java @@ -0,0 +1,29 @@ +package net.javavatutorial.tutorials; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +@RequestMapping("/user/*") +@SpringBootApplication +public class MethodAndClassLevelAnnotations { + + @RequestMapping + String login() { + return("Login method called"); + } + + @GetMapping("/logout") + String logout() { + return("Logout method called"); + } + + public static void main(String[] args) { + SpringApplication.run(MethodAndClassLevelAnnotations.class, args); + } + +} diff --git a/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/RestControllerExample.java b/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/RestControllerExample.java new file mode 100644 index 0000000..a721c2a --- /dev/null +++ b/SpringImplementingControllers/src/main/java/net/javavatutorial/tutorials/RestControllerExample.java @@ -0,0 +1,21 @@ +package net.javavatutorial.tutorials; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@SpringBootApplication +public class RestControllerExample { + + @RequestMapping("/hellorest") + String helloRest() { + return("Hello World. This is produced by the rest conntroller method"); + } + + public static void main(String[] args) { + SpringApplication.run(RestControllerExample.class, args); + } + +} diff --git a/SpringImplementingControllers/src/main/resources/META-INF/resources/WEB-INF/jsp/index.jsp b/SpringImplementingControllers/src/main/resources/META-INF/resources/WEB-INF/jsp/index.jsp new file mode 100644 index 0000000..b8fcd67 --- /dev/null +++ b/SpringImplementingControllers/src/main/resources/META-INF/resources/WEB-INF/jsp/index.jsp @@ -0,0 +1,12 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ page import="java.time.LocalDateTime" %> + + + + Simple JSP Application + + +

Hello world!

+

Current time is <%= LocalDateTime.now() %>

+ + \ No newline at end of file diff --git a/SpringImplementingControllers/src/main/resources/application.properties b/SpringImplementingControllers/src/main/resources/application.properties new file mode 100644 index 0000000..3bf1cbf --- /dev/null +++ b/SpringImplementingControllers/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.mvc.view.prefix=/WEB-INF/jsp/ +spring.mvc.view.suffix=.jsp \ No newline at end of file diff --git a/SpringImplementingControllers/src/test/java/net/javavatutorial/tutorials/ControllerExampleJSPTests.java b/SpringImplementingControllers/src/test/java/net/javavatutorial/tutorials/ControllerExampleJSPTests.java new file mode 100644 index 0000000..2cd08ab --- /dev/null +++ b/SpringImplementingControllers/src/test/java/net/javavatutorial/tutorials/ControllerExampleJSPTests.java @@ -0,0 +1,16 @@ +package net.javavatutorial.tutorials; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ControllerExampleJSPTests { + + @Test + public void contextLoads() { + } + +} diff --git a/Webview.rar b/Webview.rar new file mode 100644 index 0000000..cc798f6 Binary files /dev/null and b/Webview.rar differ