lichMax
Level 40
Санкт-Петербург

Level 39

Published in the Random EN group
Level 39A list of questions:
  1. What is a web server?
  2. What is Tomcat?
  3. What are servlets and where are they used?
  4. What application launch modes in IDEA do you know?
  5. Is it possible to debug an application/servlet that is running inside Tomcat?
  6. How to set a breakpoint in IDEA?
  7. How to list all breakpoints in IDEA?
  8. Can IDEA change the value of a variable while the program is running?
  9. How to set indents in IDEA?
  10. How to set in IDEA so that { is displayed on the same line, and not on a new one?
My answers:
  1. A web server is a server that accepts HTTP requests from clients (most often browsers) and issues HTTP responses to them, usually along with an HTML page, images, file, media stream, and other data.

  2. Apache Tomcat is a servlet container developed by the Apache Software Foundation. Implements the servlet specification and the JSP (JavaServer Pages) and JSF (JavaServer Faces) specifications. Allows you to run web applications, contains a number of programs for self-configuration. It can act as a standalone web server, as content (in conjunction with Apache HTP Server), and as a servlet container in JBoss and GlassFish application servers.

  3. A servlet is a Java class that inherits from the HttpServlet class and implements any of the doGet(), doPost(), doPut(), doDelete()init()and destroy(). This class is used by the web server to process requests and generate responses to those requests. Each request is processed in a separate thread. The container container calls the method service()for every request. This method looks at the incoming request type and forwards it to the appropriate method. If this method is not implemented in the servlet, then this method is called on the super class, and an error is usually returned to the requester.

  4. An application in IDEA can be launched in two modes: normal application launch and launch in debug mode. The normal launch of an application is usually its execution. In debug mode, the application can be executed line by line. Also in this mode, you can set breakpoints (breakpoints) on some lines of code (the program will execute as usual until it encounters such a point; when it meets it, it will stop). In addition, this mode allows you to view the values ​​of variables during program execution.

  5. Yes, it can be done, and it can be done even from the IDE itself. For example, to start debugging a servlet from IDEA, do the following:

    1. Go to debug/launch settings
    2. Add Remote Configuration
    3. Next, a page is displayed where you need to change the address of the host where Tomcat is located and the port
    4. Open the catalina.bat file (for Windows) and correct the line "set DEBUG_OPTS=" in it. There you need to add the following "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1985". The last number is the port address we specified in step 3.
    5. Restart Tomcat
    6. Set breakpoints in the code in the right places
    7. Click Debug in IDEA
    8. Submit an inquiry
    9. Debug from development environment
  6. Either you can click the mouse in the field between the line number and the beginning of the line, or stand on some line and press ctrl + F8 on the keyboard , or stand on the line and select Run -> Toggle line BreakPoint from the menu at the top .

  7. Either with the keyboard shortcut ctrl+shift+F8 , or select Run -> View Breakpoints... from the menu.

  8. Yes, there is such a possibility. This can be done in debug mode. During debugging, you need to select the desired variable in the variable window and press F2 , or right-click on the variable and select " set value " in the menu that opens, and enter the desired variable value.

  9. You need to go to the settings (Settings), there select Editor , then - Code Style . There you can already change the general options, or change the indent settings for each supported file format.

  10. You need to go to the following path Settings -> Editor -> Code Style -> Java -> Wrapping and Braces , and then change the settings in the Braces Placement section (for a class, method, lambda expressions, other cases).

Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION