Get Initialization parameters
When you configure a servlet in Web. XML, or when you configure a servlet in annotations, you can configure some initialization parameters, which in the servlet can be
methods provided by the ServletConfig interface to obtain these parameters.
Example:
Servletdemo:
Package Com.servlet;import Java.io.ioexception;import Java.io.printwriter;import javax.servlet.ServletConfig; Import Javax.servlet.servletexception;import Javax.servlet.annotation.webinitparam;import Javax.servlet.annotation.webservlet;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;/** * servlet implementation Class Servletdemmo */@WebServlet (name= "Servletdemo", urlpatterns={"/servletdemo"}, initparams={ @WebInitParam (name= "username", value= "admin"), @WebInitParam (name= "password", value = "123456")}) public class Servletdemo extends HttpServlet {Private static final long serialversionuid = 1L;Private String username;private String password;Public String GetUserName () {return username;}public void Setusername (String username) {This.username = Username;}Public String GetPassword () {return password;}public void SetPassword (String password) {This.password = password;}/** * @see httpservlet#httpservlet () */public Servletdemo () {super (); TODO auto-generated Constructor stub}/*** @see Servlet#init (servletconfig)*/public void init (ServletConfig config) throws servletexception {This.username = Config.getinitparameter ("username");This.password = Config.getinitparameter ("password");}/*** @see Servlet#destroy ()*/public void Destroy () {TODO auto-generated Method Stub}/*** @see Httpservlet#doget (httpservletrequest request, httpservletresponse response)*/protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {TODO auto-generated Method StubResponse.setcontenttype ("Text/html;charset=utf-8");PrintWriter out = Response.getwriter ();Out.print ("Out.print ("}/*** @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response)*/protected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {TODO auto-generated Method StubDoget (request, response);}}
index.jsp page Source:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Operation Result:
Introduction to MVC
MVC pattern: The full name of MVC is the model View Controller, which is a popular design idea in the process of software development, which aims to isolate the model, control
System, view. Is the embodiment of a layered thought.
MVC pattern:
Model1 Model:
Model2 Model:
The Model2 development model of Java Web is the embodiment of NVC thought.
1) The JSP page acts as a view layer
2) servlet is the control layer
3) JavaBean is the model layer
4) DB database layer
Not to be continued ...
Java Web Learning (+): Servlet Learning (v)