0% found this document useful (0 votes)
24 views1 page

JSP and Servlet Programming Assignments

The document outlines a practical assignment for the SYB.Sc. (Computer Science) class at Vidya Pratishthan’s Commerce & Science College, focusing on Object Oriented Programming using Java. It includes a series of tasks involving JSP and Servlet programming, such as checking for prime numbers, user login validation, and displaying numbers in words. The assignment is dated February 27, 2025, and is signed by the InCharge and HOD.

Uploaded by

komalumbare7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

JSP and Servlet Programming Assignments

The document outlines a practical assignment for the SYB.Sc. (Computer Science) class at Vidya Pratishthan’s Commerce & Science College, focusing on Object Oriented Programming using Java. It includes a series of tasks involving JSP and Servlet programming, such as checking for prime numbers, user login validation, and displaying numbers in words. The assignment is dated February 27, 2025, and is signed by the InCharge and HOD.

Uploaded by

komalumbare7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Vidya Pratishthan’s

Commerce &Science College, Indapur


Department Of [Link].(Computer science)
Class: -[Link](cs) Subject:- Object oriented Programming using java-II

Practical Assignment-4 Date:-27/2/2025


Q1. Write a JSP program to check whether a given number is prime or not.
Display the result in red color.
[Link] a JSP program to check whether given number is Perfect or not.
(Use Include directive).
[Link] a JSP program to calculate sum of first and last digit of a given
Number. Display sum in Red Color with font size 18.
[Link] a SERVLET program which counts how many times a user has
visited a web page. If user is visiting the page for the first time, display a
Welcome message. If the user is revisiting the page, display the number
of times visited. (Use Cookie)
[Link] a SERVLET application to accept username and password, search
them into database, if found then display appropriate message on the
Browser otherwise display error message.
Q6. Create a JSP page to accept a number from a user and display it in
Words: Example: 123 – One Two Three. The output should be in red
Color.
[Link] a JSP program which accepts UserName in a TextBox and greets
the user according to the time on server machine.
[Link] a JSP script to accept username and password from user, if they
are same then display “Login Successfully” message in [Link] file,
otherwise display “Login Failed” Message in [Link] file.
Q9. Write a JSP script to accept a String from a user and display it in reverse
order.

InCharge HOD
([Link] Mahadik) ([Link] S.Y)

Common questions

Powered by AI

The JSP script handles login authentication by capturing input values for username and password and comparing them against predefined values or a database. If the credentials match, the script sets a response to include a success message within a Login.html file. If they don't match, the script redirects to an Error.html file containing a failure message. This approach provides clear logical paths for successful and unsuccessful login attempts .

Cookies and servlets work together to provide personalized user experiences in web applications. Cookies store user information such as preferences or session data on the client's browser, which servlets can retrieve and process to provide tailored content. For example, a servlet can read a cookie to determine how many times a user visited a page, offering a distinctive experience based on this data. Consequently, the user encounters a more engaging and customized interaction with the web application .

User visit counts can be tracked in a Java servlet using cookies. The servlet checks for an existing cookie associated with the user’s visit count. If the cookie is absent, it means the user is visiting for the first time, and a welcome message is displayed. The servlet then creates a new cookie or updates the existing one with an incremented counter value for subsequent visits .

A JSP program can determine whether a number is prime by iterating through possible divisors up to the square root of the number and checking for any divisors other than 1 and the number itself. To visually display the result, the program can use HTML with a style attribute to change the text color to red, effectively highlighting the output that indicates whether the number is prime .

In a JSP script, the dynamic greeting based on server time is achieved by retrieving the server's current time using Java's utilities like Calendar or LocalDateTime. Based on the hour retrieved, different greetings such as 'Good Morning', 'Good Afternoon', or 'Good Evening' are selected and displayed to the user. This approach ensures the greeting is always up-to-date and contextual to the time zone of the server .

In a JSP program, a string can be reversed by first retrieving user input through a form. The program then converts the string into a character array or uses a StringBuilder, which has a reverse() method. The characters are reversed, and the new string is formed by joining these reversed characters. The result is then outputted to the user. This process involves basic string manipulations readily supported by Java utilities .

To validate user credentials in a servlet, first, accept user inputs for username and password via a form. Upon submission, these credentials are passed to the servlet, where a database connection is established. An SQL query is executed to check for the existence of a record matching the input credentials. If a matching record is found, a success message is displayed; otherwise, an error message is shown. This process ensures secure and efficient credential verification .

A JSP program can enhance numeric output by embedding HTML and CSS to change the visual attributes such as font size and color of the calculated result. For instance, when calculating the sum of the first and last digits of a number, the result can be displayed in an enlarged font size of 18 and highlighted in red to make it prominent on the page. This combination of frontend styling and backend logic exemplifies how JSP integrates visual presentation with dynamic content generation .

The JSP Include directive is utilized to incorporate a separate JSP file that contains the logic to check if a number is perfect. A number is considered perfect if it equals the sum of its proper divisors. By using the Include directive, one can centralize the logic in a separate file, ensuring reusability and possibly enhanced maintainability of code. The main JSP file then simply includes this logic to determine if the given number is perfect and display the output .

A JSP program converts numeric input to word representation by processing each digit of the number and mapping it to its corresponding word. For example, the number 123 is split into individual digits '1', '2', and '3', and then mapped to 'One', 'Two', 'Three'. The program concatenates these word equivalents into a single output string. The result is formatted for display by setting text attributes, such as changing the font color to red to enhance visibility .

You might also like