JavaChap Blog Java and Technology musings for the masses

27Dec/0849

CRUD Application : Struts 1, Hibernate and MySQL

Here is my Sample Struts, Hibernate CRUD application. This can act as starting point for those who are starting to build applications on hibernate and struts. I know struts 1 is sort of out dated, but i still think there are lot of legacy applications running on Struts 1.

This application has the following features.

  • Basic Create, Update and Delete Operations
  • Security (Login Support)
  • Validation (Struts Validations)
  • Internationalization and Localization (Look at the Links on the top of page, you can change the language of the application).
  • Ant build script to build and deploy the application.

Download the source code leadapp.zip (5.66 Mb)

Building and deploying the application

  • Create a schema/user using the schema.sql  file in src/database
  • Open build.properties and modify "tomcat.home" property to point your tomcat home directory
  • Database username/password can be configured in the hibernate config file \WebRoot\WEB-INF\hibernate.cfg.xml
  • Issue "ant clean deploy" command to build and deploy the application to tomcat.
  • Access the application http://localhost:8080/leadapp  (assuming tomcat is running on 8080 port)
  • username/password is user@javachap.com/javachap

I hosted this application on stax.net, access it from here http://hw4999.dvkvarma.staxapps.net, please write in the comments section if you have any problems running the application.

Application Screenshots

Login Page

Lead Listing Page

Lead Create Page

Comments (49) Trackbacks (0)
  1. Why are people still using struts 1 ? We are in the 21st century, there are far more better alternatives.

    Thank you for the tutorial, it is really well done.

  2. Hi,

    I’m very interested in this tutorial… I did all the steps mentioned here, unfortunately when calling localhost:8080/leadapp I get the following error:

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: Exception in JSP: /index.jsp:1

    1:

    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

    root cause

    org.apache.jasper.JasperException: Exception in JSP: /login.jsp:8

    5:
    6:
    7:
    8:
    9:
    10:
    11:

    Can you tell me what I’m doing wrong? Do you need the whole stacktrace?

    Any help would be really appreciated – keep the tutorial going :)

    Stefan

  3. I tried the example online at http://hw4999.dvkvarma.staxapps.net but theres some problem with the login step… someone can help me with that thing please.

    Thanks a lot.

  4. hi guys. I tried to tests the example online at http://hw4999.dvkvarma.staxapps.net but there’s some errors (we need all the files about struts tags: html, beans, etc).

    I already created the lead database and I compiled the sorce code at my pc fixing some errors that I find, but… there’s sme error with the login. PLease someone could help me, Please.

    Thanks a lot.

    Dieg.

  5. I also try the example and you can fix the tomcat problem adding the file: “struts-bean.tld”

    Rergards

  6. Hi,

    thank you for this code. But i think it would be best if you have a step by step tutorial :)

    Im really keen on learning struts

  7. I detected the same error you mentioned, at this time if you try to do the loging in the example even if you use the user and password correct (user@javachap.com and javachap) appears the frase: Invalid User name/password.

    Please please, if the author could fix that thing I’ll be super hiper happy. Please. Thanks a lot

    l

  8. Please someone can help me with the problem in the login? Thanks a lot!

    Marios Res

  9. When I try to log the application the message “Invalid Email/Password. Please try again.” appears again. I’m using Eclipse and Tomcat to test the source code, and Tomcat console shows an error with hibernate session, I don’t know what’s wrong, Please someone could help me with that.

    Thanks
    Leandro
    Brazil- South America

  10. Dear friends I downloaded the source but I found a problem about the loggin…someone could help me please.

    Thanks a lot

    Crist

  11. Dear friends I’m trying the online example and I found the follow tomcat error:

    org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 8

    5:
    6:
    7:
    8:
    9:
    10:
    11:

    You could fix it if you include the struts-bean.tld file in your WEB-INF file in your tomcat istallation.

    Thanks and PLEASE if someone can help me with the problem about the loggin I’ll be happy.

    Crist

  12. Great application :)

    Is it OK to modify little bit for personal use only?

    Thank you!

  13. Dear Imsev Benichou.

    You mentioned you have already the application working. Please could you help us about the loggin problem?

    Thanks a lot.

    Dave

  14. @Imzey Benichou
    Yes you could !! No Problem

  15. @Dave Sumners
    Dave can you send me the stack trace, I can help you to fix the problem

  16. @Leandro Escobar
    Sorry i changed the password for security reasons.. Now created the user again.. u can login now… using user@javachap.com/javachap

  17. thanks for the project sources. with some minor changes i could make it work on netbeans 6.5 with glassfish v3 prelude. i could send you a war file, that will likely help a lot of users in getting upto speed.

    also, just as an fyi, although the application works fine, i noted from glassfish logs that there were ‘severe’ errors and some related ‘warnings’ later. It looks like there are some kind of systemantic bugs in javassist.jar that might explain severe errors of ‘Javassist Enhancement failed’ due to ‘java.lang.NoClassDefFoundError:’ found at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:342). these errors do not seriously impair the application at this point, so i am not debugging further.
    thanks.

  18. I try to run this application in my system earlier it was showing some errorin login.jsp and resourcebundle file but now its working fine. its a awesome application.

    Thanks & Regards
    Mitul

  19. The error you are seeing in login.jsp that is tomcat server problem. check your application is running only tomcat server not other server.
    Also please check path in a resource bundle in struts-config.xml file.

  20. Great blog you got here…keep up the good work.

  21. Vijay,
    Thanks a lot, a great tutorial.
    This application is working in my computer. I’m very happy.
    Best Regards

  22. Hi, I am planning to host mysql and hibernate applicaiton in stax. I cudnt able to connect thru the mysql thru jdbc.url. Please look into this blog for exact problem and my configuration files.

    http://developer.stax.net/profiles/blogs/web-application-with-struts2?xg_source=activity

    Can you let me know how you connected to mysql? can u send me across hibernate-cf.xml configuration.

    Thanks
    siva

  23. i downloaded the files in my system deployed it in tomcat 6 and created the database lead in MySql.But if i add a user in the user database and log in with the added email and password it does not login. It works only for username:user@javachap.com and password:javachap are you retriving values from datbase and validating for login or ypu are using some static values. Please help me Mr.Java Chap

  24. @arun

    Perhaps you are right but once you recompiled it.. you will be able to get it with your new login…

    It appears that hibernate caches the user data and hence ignores the dynamic entry directly via db.

    Gautam

  25. Hi all,

    i am not able to download source code from here. please any one can send me the whole running source code. (arbindnegi@gmail.com)

    @ JavaChap : please send me the code on my mail id. (arbindnegi@gmail.com)

  26. i am getting the following error messages while try to login to leadapp with (userid-user@javachap.com,password-javachap).
    Invalid Email/Password. Please try again.
    could you please help me out to resolve.

    Thanks in advance….

  27. hi there, thanks for your tutorial..

  28. hello, thanks for the good tutorial..
    there’s an error if I click delete button on the lead listing page, it happens when there’s no data in lead lists.

  29. wonderful, worked like a charm on the first try. I’m using jdk1.6.0_22, tomcat 7.0.4, mysql 5.1.53, many thanks

  30. Nice tutorial. Initially I had trouble building with ant as the script is throwing error complaining “tomcat\common\lib” doesn’t exist. So, I removed line “” from build.xml and it compiled without any errors. I then had to move the leadapp.war file to tocat\webapps folder.

    It is all working now. Again, thanks for the great tutorial.

    I am using Tomcat-7.0.23, struts-1.3.10 and MySQL 5.5.20.0

  31. For some reason, it is not taking the XML tags. The line I removed was the common/lib line where it references “servlet-api.jar”

  32. hi there , it’s a good application but i have a problem to login I use jdk.1.6 , mysql 5 and tomcat 7
    the code is perfect without any error but when I log I have this error
    java.lang.ExceptionInInitializerError
    com.javachap.utils.HibernateUtils.(HibernateUtils.java:22)
    com.javachap.service.impl.UserServiceImpl.authenticate(UserServiceImpl.java:45)
    com.javachap.web.controller.LoginAction.execute(LoginAction.java:29)

    if some one can help me to login please.
    this request is correct?? “from User user where user.email= :Email and user.password= :P assword”;

    thank in advance.

  33. hi there , it’s a good application but i have a problem to login I use jdk.1.6 , mysql 5 and tomcat 7
    the code is perfect without any error but when I log I have this error
    java.lang.ExceptionInInitializerError
    com.javachap.utils.HibernateUtils.(HibernateUtils.java:22)
    com.javachap.service.impl.UserServiceImpl.authenticate(UserServiceImpl.java:45)
    com.javachap.web.controller.LoginAction.execute(LoginAction.java:29)

    if some one can help me to login please.
    this request is correct?? “from User user where user.email= :Email and user.password= :P assword”;

    thank in advance.

  34. i want to use this example by using sql server database.. for that what changes i need to do for the tables..? please any body help me..

  35. can any body tell me how to deploy this application on jboss or weblogic..? what are the changes in build.xml file… plz….

  36. That is really a good example….it helped me a lot
    Thanks……

  37. The application is currently unavailable

  38. I am not able to access this application through http://hw4999.dvkvarma.staxapps.net url. I got the below error may be tomcat is not running.

    HTTP Status 404 – Not found

  39. This is really good example. Initially it was not working but did some modification and worked fine.
    Thanks a lot. It will help me understand lot of things in better way.
    Can you please post some other real example like this??

  40. I have a browser mozilla firefox with language spanish and the solution for the following error is add this files properties:

    ApplicationResources_es.properties
    ApplicationResources_es_ES.properties
    ApplicationResources_es_MX.properties

    ******************************* ERROR ********************************************
    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: Exception in JSP: /index.jsp:1

    1:

    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

    root cause

    org.apache.jasper.JasperException: Exception in JSP: /login.jsp:8

    5:
    6:
    7:
    8:
    9:
    10:
    11:

  41. Hi all,
    i am not able to download source code from here. please any one can send me the whole running source code. (faridbelkcm@gmail.com)
    Thank you,

  42. Great work JavaChap,, thank you for this article.

    i executed it over Tomact 7

    - update the build.xml — i removed the floder “common” form one target
    - update the hibernate.cfg.xml to match your db username and passowrd
    -:put the bin of ant on the path enviornment
    - put the leadapp folder inside ant\bin
    - open command line
    - move to c:\ant\bin\leadapp and write : ant clean deploy
    - localhost:8080/leadapp


Leave a comment

No trackbacks yet.