Login form using Spring MVC part 2


LoginService:

LoginServiceImpl class:

In the LoginController we have to modify the validation logic to use the service class for validating the user. LoginController class:

For creating full login site we should add Hibernate and MySql driver dependencies in pom.xml file. Another thing is to add applicationContext.xml file for initializing Spring and Hibernate related components. For example bean definition for MySQL dataStructure and sessionFactor which will be used in DAO classes.

Thera are also a few changes in: web.xml:

Login form using Spring MVC part 1


For Energy Billing System I want to add login screen for the user that will be displayed before access to user panel. The user can enter username and password, click submit button to proceed the login. For this purpose, I create a simple database in mysql.

Create a table called: users, by using fallowing sql:

Checking information about table that we created:

Added two records into users table:

Now in a database, we should have two records. Next step is to create a model class. This Entity is mapped to the “users” table.

Created DAO class interface:

For now is a small part of login implementation. In the next post, I will present complete implementation.


Reference:

Initial controller, view and dispatcher servlet configuration


For the last few days, I have not had time to work on the project. Now there is simple page displayed as an initial project page.

Added spring framework dependencies in pom.xml file:

Simple view:

Controller:

Created dispatcher servlet configuration:

The picture above presents the basic appearance of the page that will appear after run changes. For now, there are not many changes, but it is a necessary attitude to make new changes and work on the application.


Reference:

Packages in java

Java allows to a group class and organizes them into packages. Packages are very simple and useful mechanism to organize, easily locate files, reuse code, use libraries and also save time. In real life, there are situations when we can tray to create the class in the same name. This provides to namespace collisions. Packages also help to prevent that kind of problems.

How to use a package

The class can use all of the classes from their package and all of the public class from packages that belong to other pancakes. To get access to the public class from other packages we can do it in two ways:

  • Call a full name: com.somePackage myClass = new com.somePackage();

However, it’s not a very practical way. Easier and much faster way is to use keyword: import. This keyword allows for easier use of a class from another package.

Of course, we can import all class from the package by add *, for example:

Adding a class to the package

To add class to package first we must to add package name on the beginning of source file, for example:

If we don’t add package name, a class will be placed in a default package. This package doesn’t have a name.

Part of the program that is listed bellow describes that HelloController.java belongs to com.billingsystem.controller. Therefore file HelloController.java must be stored in com/billingsystem/controller:

Maven #01 ~ What is Maven?

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting, and documentation from a central piece of information.

Primarily used for Java-based projects but that can also be used to merge projects in other programming languages like C# and Ruby. Many integrated development environments provide plugins for Maven. Typical tasks if a build tool is a compilation of source code, running test and packaging results into jar files. Maven can also perform related activities, for example, creating websites, uploads build results or generate reports.

Automating process of creating the initial project structure for Java application is very important, especially when doing it manually may take much more time and also there is a possibility for making typos during using some commands in the console, the last one is very frequent.

A little bit history.
Originally Maven was designed to simplify building process in Jakarta Turbine project.

What for?
Maven can be used for:

  • handle dependencies and intermediate dependencies
  • easy selection of tasks from the command line
  • versioning and tagging code
  • a large number of plugins to simple and complex tasks
  • Integration with all IDE such as Eclipse, NetBeans or IntellyJ
  • ability to manage a number of the modules of the project at a time
  • support for:
    • unit tests
    • integration tests
    • load tests
    • performance tests
  • application builds
  • generating documentation
  • releases
  • mailing list management

Maven is working according to the Convention Over Configuration pattern, which means that the configuration requires only those components that are nonstandard or user will want to adopt them for their needs, and the same configuration change can also be found under only one file – pom.xml.
Developers can build Maven project without the need to understand how the individual plugin works.

Installation
I use several systems start from Linux, Windows and Mac OS X machines. For this post, I will use Mac OSX.
Open terminal and type: brew install maven

If we have already maven installed, in a terminal should appear:

After installing Maven should check if everything is working properly, this purpose should be in the command line to run Maven and check the versions of what was installed:

As you can see installation is not difficult in inches. Some different looks to install Maven on Linux and Windows.

Before we turn to the creation of the first project we need to discuss a matter of a few, namely what they are:

  • artefact
  • group
  • version

The artifact is a name that identifies the project in the group. The group allows you to organize the namespace in which it is the artifact.

Both the group and artifact and version uniquely identifies the library of which we want to use. There is also something like what is called a plugin and archetype. The plugin is a special Java language, class in which performs the appropriate actions on the basis of asking configuration, for example, to pack compiled class to a jar file, generate documentation. An artifact is a specific plugin using which created them st project. It contains in its structure mapping of tree directories a new project, or file pom.xml contains basic project data.

Generating project
To generate maven project we have two options. First from a console and second from IDE.
Creating maven project looks as follows:

With this command Maven generates a Java project:

This last step can take some time depends on how much RAM memory do you have (These days it’s 16 GB).
Structure of the genereted project looks like follows:

We have generated whole Maven project structure Java source code. Maven created App.java class which is just simple “Hello World” program. We have also can see AppTest.java that is the simple test class. In root catalog, we can find our pom.xml file:

To compile Java source code we need to trigger: mvn compile in root project directory. This command runs through all life cycle phase, which is needed to compile a project.

To run test phases instead to run a full build we need just to trigger: mvn test

To clean project and remove all generated files from ./target directory we can use: mvn clean


Reference:

  1. Apache Maven Project
  2. MVN Repository
  3. IntellyJ IDEA Maven
  4. Supported tags and respective Dockerfile links

  5. Jakarta Projekt

  6. Five things you didn’t know about Maven by IBM

  7. Introduction to Apache Maven 2

  8. Deployment of artifacts with FPT

  9. Maven Wrapper GitHub repo

Get Notice 2017

An interesting idea has been spread in polish software development world. Recently is called “Let them know you” (“Daj się poznać” in Polish). It’s all about developing an open-source project and blogging to share the knowledge about this. Last year I also participate in this event but from lack of a time, I didn’t finish my project. I hope that in this year I will be able to complete my project as I planned.

What this mean for me and especially for others?

For me, it’s a time to challenge myself with creating something to solve one simple problem. And for others make live easier. Another thing I would like to achieve is to return to writing. A few years ago when I was 17 years old I started with the first blog. It was not pretty much easy for me. So after a few posts, I closed my blog. Then I didn’t know the value od sharing of knowledge. Currently, I approach things a little different.

Problem
I don’t like to guess how much I will have to pay my bills in a given quartal or first/second half of the year. In the other hand, no one likes to pay bills. Especially high bills which nowadays it’s not easy. Please imagine that suddenly comes a high electric or consumed water bill. We don’t need to imagine because it usually is. So how to be prepared? How to reduce consumption? How to compare consumption with the previous billing periods?

Solution
A solution is an application that can allow users to check a status of used energy in each time. Compare how much energy has been consumed in each month.

I think that such an application can be helpful and will help solve one basic problem, namely notifies you of the charges on the present day user. Unfortunately, this is already on the side of us will lay what do we do with this information. Do you start to save and manage their resources wisely, or we will be wasteful.

Technology
In this project, I want to use Java, Spring, R language to data visualization and also python. Probably there will be the android application, but for now, I want to concentrate on core application.