Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The common method headers in the Servlet method

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report