Create an ssh project in IDEA and implement a simple login function example

Because I haven't used SSH for a long time in the past two days, I simply made a login function example on IDEA. I will show you the steps and code examples! ! ! ! ! ! !

The software environment is: IntelliJ IDEA 2017.1.2 + Spring + Struts2 + Hibernate (Ssh)


Engineering steps:

1. Open IntelliJ IDEA 2016.1.2, go to File->New->Project in the upper left corner to get the following page

1> Join Spring


2> Add Struts Pull down the scroll bar on the right side of the picture above to see struts

3> Join Hibernate and continue to pull down the scroll bar on the right side of the figure above to see Hibernate

4> After selecting, you can click next, enter the name of the project you like and select the place where the project is to be placed, click finish, and then the following green box will appear to start downloading the dependent package. This place needs to be connected to vpn, otherwise some packages may be Can't download.

5> Wait until the download is over and see the following structure, the construction is successful

instance login

1. Start the mysql database and create the database and login user table

2. In the lower left corner of the editor, hover the mouse over the small red box and a menu will pop up, then click on Database


3. After the previous step, a new tab will pop up, then click the image below


A new window will pop up after that, enter the database related information


Then click MySQL to download the relevant driver, and copy the content of the red box (for example, mine is "C:\Users\Administrator\.IntelliJIdea2016.1\config\jdbc-drivers\mysql-connector-java-5.1.35-bin.jar ”), click ok


As shown in the figure above, click + in the figure to display the location information of the mysql driver.

Then click on the image below


Click the red box on the right to get a new window, and then continue to press the red box all the way.


Then go to the new pop-up window and put the file address just copied (mine is "C:\Users\Administrator\.IntelliJIdea2017.2\config\jdbc-drivers\MySQL Connector\J\5.1.40\mysql-connector-java -5.1.40-bin.jar") into the red box and click OK (click OK for subsequent pop-up boxes)


5. Click the icon in the lower left corner to make it appear the leftmost menu Persistence



Click Persistence->Right-click SSH_DEMO (in the red box )->Generate persistence Mapping->By Database Schema

After one click, you will get a new pop-up box, select the data source, click package to add a new package, we call it com.entity here, and enter the value of Entity suffix "Entity"


After clicking OK, check the table to be mapped and select Session Factory


6. Place SSH_DEMO / src / spring-config.xml



Next, you need to add 2 rack packages, download spring-web-xxxRELEASE.jar, click the Project structrue button on the upper right side or press the shortcut key ctrl+alt+shift+s and then click the image once


Then enter spring-web in the pop-up box and press Enter, select a version corresponding to spring from the search results, and download struts2-spring-plugin-xxxxx.jar in the same way


After downloading, leave the two destination rack packages and leave the remaining packages to prevent duplicate packages (special attention must be paid to the version of the jar package, otherwise it will affect the successful startup of the project!!!!)

If there is an error about log4j during the startup process, you need to download the three jars log4j-core.jar, log4j.jar and log4j-api.jar, and remember that the versions are unified.

7. Next is some code writing of login and some configurations of spring-config.xml, struts.xml, web.xml, here I will not describe the writing in detail and directly attach the code package in the src and web directories

To view the code click: http://download.csdn.net/download/byy8023/10050561

8. The last step is to integrate the tomcat operation

Click on Antu in the upper right corner (because I have configured everything and will see the words "tomcat8")

Configure the tomcat path in the new pop-up box and click OK


After the last small step, click the run button or the shortcut key shift + F10 to see the page



Finally, I solemnly remind everyone that when downloading the jar package of the SSH framework, you must pay attention to the compatibility of the version. If it fails to run successfully, please analyze the problem from the following points. Personal opinions are for reference only:

1. The written JDK and the compiled JDK are not the same version, which will lead to inability to run. The project-properties-Java Compiler-Compiler compliance levle is the same as the JDK version of Myeclipse-Preferences-Java-Installed JRE.
2. There is an error in web.xml, be careful Check, this time the problem web.xml is no problem.
3.jar package should be imported completely, but it should not be imported too much, otherwise it will cause an error. The missing jar package this time is log4j-api-2.7.jar to solve the problem
4 .<action name = "hello" class = "cn.struts.action.HelloAction"> without the .java suffix


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324197490&siteId=291194637