– notes, snippet codes, and my journal

Session in Spring MCV

leave a comment »

It good article about session in spring mvc, so i bookmarked in my blog :D

What is the HTTP session? What for it exist? I hope you know that HTTP is a stateless protocol, that’s mean that there is no permanent connection between a browser and server. And as the result server doesn’t know who is an initiator of a request, even if an application has just one user. The session is a tool for identifying of requests author. The previous sentence is rough enough, but it explains the main purpose of the sessions. Every user gets it own session with unique identifier when he visits site first time.

Written by snippetjournal

March 26, 2015 at 3:04 am

Posted in Uncategorized

Spring 4 Maven Dependency : misbehaviors error spring mvc

leave a comment »

It was very late, almost midnight and can not resist to write this problem that i get. almost spent more than one hour to figure out what wrong with this spring mvc error.

This is my second time develop java web from scratch using spring mvc and i use spring web version 4.x.x. After prepare the all xml configuration there is no problem. All went well until i want to redirect the url from index.jsp to another url that will invoke my controller and the confusion begin :(

SEVERE: Servlet.service() for servlet [eleveniaTest] in context with path [/elevenia-test] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoSuchFieldError: STANDARD_NUMBER_TYPES
at org.springframework.web.context.request.ServletRequestAttributes.<clinit>(
at org.springframework.web.servlet.FrameworkServlet.buildRequestAttributes(
at org.springframework.web.servlet.FrameworkServlet.processRequest(
at org.springframework.web.servlet.FrameworkServlet.doGet(
at javax.servlet.http.HttpServlet.service(
at org.springframework.web.servlet.FrameworkServlet.service(


After goggling and trying figure out what the cause, some post in stackoverflow tell to add maven dependency eclipse configuration, and refer the path web-inf/lib.

But it doesn’t solve my problem, because the configuration its already there and the culprit clearly not the maven lib config.

So after looking my previous spring 4.x project there is additional configuration in pom.xml that force all the spring libs 4.x to avoid this misbehavior

<!– Force the version of all the spring jars (core, beans, context, …)
pulled by spring-data-jpa:1.3.4.RELEASE to 3.2.x when spring-data pulls the
3.1.x versions to prevent some misbehaviors of maven which sometimes pulls
both 3.2.x and 3.1.x versions of spring-core, spring-beans and spring-context –>

Its likely somehow the spring data jpa pulls between spring version 3.1.x or spring 3.2.x from spring core into libs. so caused above error

Written by snippetjournal

March 11, 2015 at 4:43 pm

Posted in Uncategorized

Eclipse STS Trivial Configuration

leave a comment »

Lately i was using eclipse STS to develop some information system, after a long time using netbeans, using STS is so much painful for me.

Yes eclipse STS fan boy can hate me, hatters gonna hate after all …  :P

In netbeans some trivial things like deployment process using eclipse, synchronized source in tomcat, auto deploy, maven configuration, and another deployment issues in tomcat,  are never occur when i was using netbeans

That kinds of trivial thing some time are so painful, you must configure it so you will have good sleep at night. :D , in the netbeans this kind of configurations are the default configuration, and i can say that netbean have improve so much than STS, it more easier develop using netbeans :P. You can focus on development rather get confused by configure your IDE to behave like you want to.

this are some STS issue that sometime occur when i was using it for development.

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.core.DefaultInstanceManager.loadClass(
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(
at org.apache.catalina.core.DefaultInstanceManager.newInstance(
at org.apache.catalina.core.StandardContext.listenerStart(
at org.apache.catalina.core.StandardContext.startInternal(
at org.apache.catalina.util.LifecycleBase.start(
at org.apache.catalina.core.ContainerBase$
at org.apache.catalina.core.ContainerBase$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$

this error occur because your maven dependency or your libs that manage by maven didnt included in tomcat deployment. here the solution :

right click in your project, properties – deployment assembly : add java build path entries – maven dependencies – finish.

refresh your poject, re-build , clean your tomcat resources to make sure it will deploy your new source (right click in tomcat server – clean), after that run your project in tomcat server.

another error is un-synchronized source in your tomcat server when you trying to deploy it. i spent more than an hours facing this kind of issue, i try to clean the project using maven, clean – build project in STS, rebuild and clean tomcat resources for many times.

this probably occur because STS didnt refresh the resources in workspace and tomcat when the project rebuild in STS or netbeans.

the solution you must configure STS to automatically refresh the resources, go to preferences – workspace : checklist this options :

  • build automatically
  • refresh using native hooks or pooling
  • refresh on access
  • save automatically before build

and another tricks is when you have many resources file like CSS or java script you must configure STS memory more than the default memory, just change memory size in STS.ini in your STS installation location :



Written by snippetjournal

January 17, 2015 at 3:42 am

Posted in Uncategorized

Tagged with , , , , ,

Ajax posting as Data Map in spring MVC

leave a comment »

post data dengan ajax sebagai data Map di java dan spring mvc

Javascript code :

	param = {
		xx1 : "xx",
		xx2 : "xx",
		xx3 : "xx",
		xx4 : "xx"
	// post data when page loaded
	var postParamForDatatable = $.ajax({
		url : urlContext + "post/param/xxx",
		type : "POST",
		contentType : "application/json",
		data : JSON.stringify(param)

	console.log("get data ");
	// callback handler that will be called on success
	postParamForDatatable.done(function(repliedData) {
		console.log("repliedData "+repliedData);

	// callback handler that will be called on failure, textStatus, errorThrown) {
		alert("The following error occured: " + textStatus, errorThrown);

	// callback handler that will be called regardless if the request failed or
	// succeeded
	postParamForDatatable.always(function() {
		console.log("callback handler that will be called regardless if the request failed or succeeded");

Java controller dengan spring mvc

	@RequestMapping(value = "/post/param/xxx", method = RequestMethod.POST)
	public @ResponseBody String getdataParam(@RequestBody Map<String, Object> searchParam, HttpServletRequest request, HttpServletResponse response) {
		System.out.println("================ "+searchParam);
		return "ok";

Written by snippetjournal

January 15, 2015 at 6:57 am

Posted in Uncategorized

Get Context Url from Java Servlet

leave a comment »

Get Context Url from Java Servlet

<%@taglib prefix="c" uri=""%>
<%@taglib prefix="fn" uri=""%>
<c:set var="req" value="${pageContext.request}" />
<c:set var="url">${req.requestURL}</c:set>
<c:set var="uri" value="${req.requestURI}" />
<c:set var="urlContext" value="${fn:substring(url, 0, fn:length(url) - fn:length(pageContext.request.requestURI))}${pageContext.request.contextPath}/" />

Written by snippetjournal

December 31, 2014 at 2:55 am

Posted in Uncategorized

Hibernate : Understanding First level and Second level cache

leave a comment »

found this article, a good article and easy explanation tutorial :)

note :

  • SessionFactory provides session, session maintains cache.
  • How will session cache object get update from DB if any changes happen. Will get update automatically or explicitily.?

In case of single session, your application code always update this cache object so it is always updated. Hibernate takes care of synchronizing the changes with database at time of flushing the session.

Now consider another example:

machine 1: reads the data and returns it for editing somewhere else
machine 2: also reads the data for modification
machine 1: updates the data and commits.
machine 2: tries to do an update and commit.

What will happen when the second machine tries to commit its changes? Hibernate will see that the data has changed while machine 2 was working on the data. That is, machine 2’s update is on stale data. Hibernate can’t always merge the two changes (nor is that always desired behaviour), so it rejects the second update by throwing org.hibernate.StaleObjectStateException.

The simplest solution, perhaps, is to add a version field using @Version on your data objects. Hibernate will automatically maintain the “version” of the data. Whenever an update takes place, the version will be changed automatically by Hibernate. Your job is the check that the version hasn’t changed between when you read the data and when you update the data. If they don’t match, you can do something to handle the problem (i.e. tell the user). There are some more sophisticated techniques for preventing concurrent updates, but this is the simplest.

Written by snippetjournal

November 24, 2014 at 3:33 am

Sonatypes Maven References

leave a comment »

Written by snippetjournal

November 20, 2014 at 2:47 am

Posted in Uncategorized


Get every new post delivered to your Inbox.

Join 77 other followers