Development Log function
In the last article, we completed the building (refer to Advanced Java Development class notes (c)) web services, can now start preparing to develop code.
First, in the main folder, create a java
folder used to store our code, this folder is set to Sources Root
:
Secondly, we are in java
this folder, create a controller
package, create a new LoginController
class:
At this point we you can start preparing to develop a login function. First of all, we first configure the Servlet in web.xml:
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>cn.edu.mju.project2.controller.LoginController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
Which <Servlet-name>
is to be registered Servlet name <Servlet-class>
is the address to be registered Servlet class, and to bring the package path. <Servlet-mapping>
We are used to configure the access path components registered, including two nodes inside, is a <Servlet-name>
previous written Servlet
keeping the other is <url-pattern>
to configure the components of the access path.
If you think the above method is too much trouble, you can directly LoginController
configure it:
@WebServlet("/login")
At this point WebServlet there was an error, since no import jar package is due, we click Import class
can be.
Once configured WebServlet, due LoginController
to inheritance HttpServlet
, so we have to be rewritten doGet and doPost:
doGet:
doPost:
Tip: If you want to display Chinese on the web interface, you need to add the following two codes in the code ( here, for example by doGet code):
Let's look at the current results, run the program, open the browser, enter the previously set a good URL:
Finally, do not forget the code will be submitted to the local development of the warehouse, and push to the remote repository.