Get the App
SLTechnology News&Howtos  ›  Development  › 

The common method headers in the Servlet method

Shulou Source: shulou.com Published: 2022-06-02 07:42:20 10月12日 Update

Editor to share with you the commonly used methods in the Servlet method head those, I believe that most people do not know much, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to understand it!

◆ parseTextMessage () method

In this example: a data acceptance class is defined. The parseTextMessage () method accepts a set of objects passed from the form and their values. When we do some product development, such as custom forms, we often do not know how many objects are transmitted. For such a problem, the program cannot know. After using this method, we can report that all the objects have been obtained at once. Take a look at this example:

Private void parseTextMessage (HttpServletRequest request) {Enumeration names; / / enumerate all objects passed by client String name; / String [] value; / accept all objects names = request.getParameterNames (); while (names.hasMoreElements ()) {/ / get the object name name = (String) names.nextElement () / / relocate the value of the object value = request.getParameterValues (name) based on the object name; / / put the object name and value into a class whose code has put (name, value) in the previous exercise;} / / get an ID of page, why set page id, pageID = getPostPageID () in the java rule / / get the transaction id. If there is a transaction, trxID = getPostTrxID ();}

◆ getJSPBeanInSession () method

This is an Imax O management class. This method returns jsp data from session based on page's id, and it is also true to use getSession (true). GetAttribute (pageID).

Private JPC_JSPBean getJSPBeanInSession (String pageID) {return jsp data from session according to the id of the page return (JPC_JSPBean) request.getSession (). GetAttribute (pageID);}

◆ dispatchTransaction () method

This method gets a set of instances of the class and starts the transaction.

Public void dispatchTransaction () {JPC_Transaction trx = null; String classList [] = getTrxClassList (getTrxID ()); try {for (int I = 0; I < classList.length; iTunes +) {trx = (JPC_Transaction) Class.forName (classList [I]). NewInstance (); if (trx! = null) {trx.setIOManager (this) Trx.start ();} catch (ClassNotFoundException e) {e.printStackTrace ();} catch (InstantiationException e) {e.printStackTrace ();} catch (IllegalAccessException e) {e.printStackTrace ();}}

◆ putJSPBeanInSession () method

Put the data class of jsp and the ID of a jsp page into session.

Private void putJSPBeanInSession (String pageID, JPC_JSPBean jspBean) {/ / put the data class of jsp and the ID of a jsp page into session. Request.getSession () .setAttribute (pageID, jspBean);

◆ sendPage () method

Private void sendPage (String pageID, JPC_JSPBean outJSPBean) {/ / store the page id and data in session if (outJSPBean! = null) {putJSPBeanInSession (pageID, outJSPBean);} / / get the file data String jspFileName = getJSPFileName (pageID) according to the file id; / / get a RequestDispatcher RequestDispatcher rd = context.getRequestDispatcher (jspFileName) based on the jsp file name If (rd! = null) {try {/ / call jsp rd.forward (request, response);} catch (ServletException e) {} catch (IOException e) {} these are all the contents of this article entitled "Common method headers in Servlet methods". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Methods objects data transactions names files articles pages commonly used examples content forms not so products product development code most instances file names times Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Xiaomi Shulou Technology Microsoft