Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

‭Short Answers:‬

‭8. Advantages of JSP over Scriplet CGI:‬


‭●‬ S ‭ eparation of Concerns:‬‭JSP separates HTML presentation‬‭from Java business logic,‬
‭promoting maintainability and cleaner code.‬
‭●‬ ‭Security:‬‭JSP code executes on the server, mitigating‬‭s ecurity risks associated with‬
‭c lient-side scripting (CGI).‬
‭●‬ ‭Component Reusability:‬‭JSP allows for creating reusable‬‭c omponents (tags), promoting‬
‭m odularity and code reuse.‬
‭●‬ ‭Error Handling:‬‭JSP offers better error handling mechanisms‬‭c ompared to CGI.‬

‭9. Advantages of JSP over Scriplet:‬


‭●‬ R ‭ eadability:‬‭JSP separates logic (scriptlets) from‬‭presentation (HTML), making code easier‬
‭to read and maintain.‬
‭●‬ ‭M aintainability:‬‭Changes to logic can be made in scriptlets‬‭without affecting HTML structure.‬
‭●‬ ‭Error Handling:‬‭JSP provides better error handling‬‭c apabilities compared to scriptlets‬
‭embedded directly in HTML.‬
‭●‬ ‭Reusability:‬‭JSP allows for creating reusable components‬‭(tags), promoting code reuse.‬

‭1 0. Page Directive in JSP:‬


‭●‬ P ‭ age directives control aspects of the JSP page, such as:‬
‭○‬ ‭<%@ page ... %>: Configures the page's character encoding, content type, error handling,‬
‭and more.‬
‭○‬ ‭<%@ include file="..." %>: Includes another file (JSP or HTML) into the current page.‬
‭○‬ ‭<%@ taglib uri="..." prefix="..." %>: Imports a custom tag library for using custom tags in‬
‭the JSP page.‬

‭ 1. Difference between Scriplet Tag (<% ... %>) and Declaration Tag (<%! ...‬
1
‭% >):‬
‭●‬ S ‭ criplet Tag:‬
‭○‬ ‭Embeds Java code within the JSP page.‬
‭○‬ ‭Used for calculations, variable manipulation, and logic execution.‬
‭●‬ ‭Declaration Tag:‬
‭○‬ ‭Declares variables, methods, and classes within the JSP page.‬
‭○‬ ‭These elements have the same scope as local variables in a servlet.‬

‭1 2. Form Validation in JavaScript:‬


‭●‬ F ‭ orm validation ensures user input conforms to expected format or type (e.g., checking if a‬
‭field is filled, ensuring a valid email address).‬
‭●‬ ‭JavaScript provides methods like .value to access form field values, and conditional‬
‭s tatements to check validity before form submission.‬
‭1 3. this Keyword in JavaScript:‬
‭‬ R
● ‭ efers to the current object within a method or function.‬
‭●‬ ‭Used to access properties and methods of the current object.‬
‭●‬ ‭Can vary depending on the context (e.g., inside an event handler vs. a regular function).‬

‭14. Scope of Variables in JavaScript:‬


‭●‬ G ‭ lobal Scope:‬‭Variables declared outside of any function‬‭or block are globally accessible.‬
‭(‬‭Avoid overuse for better code organization‬‭)‬
‭●‬ ‭Function Scope:‬‭Variables declared within a function‬‭are only accessible within that function‬
‭and its nested functions.‬
‭●‬ ‭Block Scope:‬‭Variables declared within a let or const‬‭s tatement (introduced in ES6) are only‬
‭accessible within the block they are declared in (e.g., if block, for loop).‬

‭15. Difference between onclick and Submit Button:‬


‭●‬ o ‭ nclick Event:‬
‭○‬ ‭Can be attached to any HTML element (not just buttons).‬
‭○‬ ‭Executes a JavaScript function when the element is clicked.‬
‭●‬ ‭Submit Button:‬
‭○‬ ‭Submits a form when clicked.‬
‭○‬ ‭Triggers form validation (if implemented in JavaScript) before sending the form data to the‬
‭s erver.‬

You might also like