Peb puas tuaj yeem sau parameterized constructor hauv servlet?
Peb puas tuaj yeem sau parameterized constructor hauv servlet?

Video: Peb puas tuaj yeem sau parameterized constructor hauv servlet?

Video: Peb puas tuaj yeem sau parameterized constructor hauv servlet?
Video: Finance with Python! Short Selling and Short Positions 2024, Kaum ib hlis
Anonim

Koj tsis tuaj yeem muaj parameterized tsim nyob rau hauv cov khoom tsim dynamically los ntawm ib co software raws li nyob rau hauv Servlets . Yog koj siv Servlet interface rau sau a Servlet (es tsis txhob ncua HttpServlet), koj tsis tuaj yeem muaj tus tsim (hauv interface).

Kuj paub, peb puas tuaj yeem sau tus tsim qauv hauv servlet?

Yog lawm, Servlet tuaj yeem muaj Tus tsim , nws zoo tag nrho raws li txoj cai tab sis nws tsis yog txoj hauv kev los pib koj Servlet . Koj yuav tsum siv cov txheej txheem init() muab los ntawm Servlet interface los pib lub Servlet.

Ib tug kuj tseem nug, peb puas tuaj yeem siv tus tsim qauv siv init hauv Servlet? Cov lus teb luv luv ntawm lo lus nug no, Yog, Servlet cov chav kawm siv ua tau muaj tus tsim tab sis lawv yuav tsum yog siv init () txoj kev mus pib Servlet vim yog ob qho laj thawj, thawj zaug koj tsis tuaj yeem tshaj tawm tus tsim ntawm interface hauv Java, uas txhais tau hais tias koj tsis tuaj yeem tswj qhov kev xav tau no rau txhua chav kawm uas siv Servlet

Ib yam li ntawd, nws yog nug, yuav ua li cas constructor siv tau rau lub servlet?

Technically koj ua tau txhais tus tsim hauv servlet . Tab sis, tus tshaj tawm tus tsim ua tsis tau nkag mus rau ServletConfig cov khoom lossis pov rau ServletException. Yog li ntawd init() yog siv txhawm rau pib los ntawm kev hla cov khoom siv ntawm ServletConfig interface thiab lwm yam kev xav tau.

Dab tsi yog init parameters hauv servlet?

Servlet specification muab ib txoj kev los muab nws parameters mus rau servlet thaum nws pib. i.e. nws ib init () txoj kev ua tiav. Cov no nws parameters muaj nyob rau hauv servlet . Tsis muaj tuaj yeem nkag tau siv pej xeem String getInitParameter(String name) txoj kev.

Pom zoo: