What is the anatomy of a jsp page?
A JSP File Contents:
A JSP file can contain the following:
a. HTML contents
b. JavaScript
c. Java Code
Combining the features of the above 3 mentioned items; we get a powerful entity called the JSP. JSPs are used for the User Interface layer or the more colloquially called Front End layer of any J2EE application.
JSP Skeleton
Below is how a Skeleton JSP File would look like. (The file has to be saved as .jsp)
// Page Imports
<%@ page import = "com.xyz.ClassName %>
// Tag Library References
<%@ taglib URI = "path to Taglib file" prefix = "xx" %>
// here xx refers to the prefix with which the tag library will be referred to
// HTML Head & Title Content
// Java Script Content
// HTML Body & Form Contents
Note: Java code can be placed within the <% %> tags in the body part of the JSP page within the Body tags.
Difference between java script and java server page?
JSP in French stands for "Je suis pressé", which translates to "I am in a hurry" in English.
JSP stands for Java Server Page, which is a program that controls how things appear on a webpage. JSP is not considered a language but it is written for programs using the programming language of JavaScript.
Describe the various HTTP request methods?
HTTP defines eight methods (sometimes referred to as "verbs") indicating the desired action to be performed on the identified resource. What this resource represents, whether pre-existing data or data that is generated dynamically, depends on the implementation of the server. Often, the resource corresponds to a file or the output of an executable residing on the server. ; HEAD : Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content. ; GET : Requests a representation of the specified resource. Note that GET should not be used for operations that cause side-effects, such as using it for taking actions in web applications. One reason for this is that GET may be used arbitrarily by robots or crawlers, which should not need to consider the side effects that a request should cause. See safe methods below. ; POST : Submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both. ; PUT : Uploads a representation of the specified resource. ; DELETE : Deletes the specified resource. ; TRACE : Echoes back the received request, so that a client can see what intermediate servers are adding or changing in the request. ; OPTIONS : Returns the HTTP methods that the server supports for specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource. ; CONNECT : Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.[3]
How should a meeting use a gavel?
A gavel is typically used by the chairperson to signal the start or end of a meeting, to call for order, or to bring attention to important points being made. It should be used respectfully and sparingly to maintain decorum and attention during the meeting.
What is Servlet API used for connecting database?
The Servlet 2.3 API consists of two packages: javax.servlet and javax.servlet.http. The base functionality is defined in the javax.servlet package whose classes and interfaces outline a generic, protocol-independent implementation. This means you can use it for non-Web applications, too. The javax.servlet.http interface defines classes and interfaces that are specific to the Hypertext Transfer Protocol (HTTP).
Can you use jsp and servlets together?
Yes, JSP (JavaServer Pages) and Servlets can be used together in a web application. Servlets handle the business logic and processing of requests, while JSP is used to create the user interface and generate dynamic content. Servlets can interact with JSP pages to pass data and control the flow of the application.
JSP Skeleton
Below is how a Skeleton JSP File would look like. (The file has to be saved as .jsp)
// Page Imports
<%@ page import = “com.xyz.ClassName %>
// Tag Library References
<%@ taglib URI = “path to Taglib file†prefix = “xx†%>
// here xx refers to the prefix with which the tag library will be referred to
// HTML Head & Title Content
// Java Script Content
// HTML Body & Form Contents
Note: Java code can be placed within the <% %>tags in the body part of the JSP page within the Body tags
How do you dynamically identify the jsp in servlet?
You can dynamically identify the JSP file in a servlet by using the request URL or request parameters to determine which JSP to forward the request to. You can also store necessary information in session attributes or external configurations to help determine the appropriate JSP to display. Finally, you can use a servlet mapping or URL pattern to route requests to different JSP files based on the URL.
What is the difference between an ASP and an ISP?
An ASP (Application Service Provider) provides software applications over the internet, while an ISP (Internet Service Provider) provides access to the internet. ISPs offer connectivity services like email, web hosting, and domain registration, whereas ASPs offer software applications for a fee.
The Servlet Context
A Web application includes many parts. It is more than just one servlet or JSP. Numerous JSPs and one or more Servlets and other supporting java classes together form the web application. To help manage an application, you will sometimes need to set and get information that all of the servlets share together, which we will refer to as context-wide.
For Example, if you want a single name using which you can refer to the application, you can set it in the servlet context and have it shared across all instances that use the application.
Ex Code:
public void init(ServletConfig config) throws ServletException
{
super.init(config);
// Get the Context
ServletContext context =config.getServletContext();
// Set the attribute
context.setAttribute("appName", "My Test App");
}
Any time you want, you can refer to this attribute in the context and get its value like below:
String appName = context.getAttribute("appName");
After the above line of code, the variable appName will have the value "My Test App
What are the advantages and disadvantages of JSP?
Advantages of JSP
1. HTML friendly simple and easy language and tags.
2. Supports Java Code.
3. Supports standard Web site development tools.
Disadvantages of JSP
1. As JSP pages are translated to servlets and compiled, it is difficult to trace
errors occurred in JSP pages.
2. JSP pages require double the disk space to hold the JSP page.
3. JSP pages require more time when accessed for the first time as they are to be
compiled on the server.
Set and get session attributes syntax in servlets and java script?
Setting and getting session attributes is fairly easy. It is the same in both Servlets and JSPs with one exception. In a JSP, you already have access to the session object, and you do not have to declare it. In a Servlet, you must get the session like this: javax.servlet.http.HttpSession session = request.getSession(); Once you have done that, you can set a session object like this: session.setAttribute("name","value"); To retrieve the value, do this: String foo = (String) session.getAttribute("name"); A couple of things to keep in mind: * The second parameter in the setAttribute method is an Object, not a String. When you retrieve the value, you have to cast it. In the example above, I am casting it to a String. * If you try to perform a getAttribute on a session attribute that does not exist, or was not set, it will return a null. * Session attributes are not available using JavaScript. You can not set or get an attribute in JavaScript. * You do NOT need to do the 'session = request.getSession() in a JSP. It is only necessary in a Servlet.
What is a session What are the different ways of session tracking in servlet programming?
Why do we need a Session?
When one page needs to share information with another, the scope of the data broadens beyond processing a single request. This is because, when a response gets committed, all the data that was held in the request that generated that response is destroyed. So, if you want that data in another page, you will be looking at a blank request object with no data in it. When such a need arises, you must send the data from one page to the server and from the server to the next requested page, whether it be the same page or another page altogether. There are several ways to share state information between requests. However, the primary or the easiest way is to use sessions.
How Do Sessions Work?
The container generates a session ID. When you create a session, the server saves the session ID on the client's machine as a cookie. If cookies are turned off then it appends the ID in the URL. On the server, whatever you add to the session object gets placed in server memory-very resource intensive. The server associates that object in memory with the session ID. When the user sends a new request, the session ID is sent too. The server can then match the objects in its memory with that session ID. This is how we maintain client state.
How do you get servlet context instance to servlet?
You can get the ServletContext instance in a servlet by using the getServletContext() method provided by the HttpServlet class, which is the base class for servlets. This method returns the ServletContext object associated with the servlet. For example: ServletContext context = getServletContext();
Write a servlet to display request header information?
Retrieving HTTP Request Header Information
The Http Request header is the area where all the details of the request are bundled. This is where the browser specifies the file wanted, date, image file support, and a lot more. Let us take a look at a sample Servlet that is going to read through the Http Request Header.
Servlet code:
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Displaying request headers
*
* @author Anand V
*/
public class ReadHttpRequestHeaderServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/HTML");
PrintWriter out = response.getWriter();
out.println("< HTML >");
out.println("< head >");
String title = "Read Request Header Example";
out.println("< title >" + title + "");
out.println("< / head >");
out.println("< body >");
out.println("< h3 >" + title + "< / h3 >");
out.println("< table >");
Enumeration e = request.getHeaderNames();
while (e.hasMoreElements())
{
String headerName = (String)e.nextElement();
String headerValue = request.getHeader(headerName);
out.println("< tr >< td bgcolor="#CCCCCC" > " + headerName);
out.println("< / td >< td > " + headerValue + " < / td > < / tr >");
}
out.println("< / table >");
out.println("< / body >");
out.println("< / HTML >");
}
}
What is the difference between servlet context page context?
ServletContext is an interface for communication with the servlet container while PageContext is an object for managing data related to a JSP page. ServletContext is used for application-wide resources while PageContext is specific to a single JSP page.
How do you create an address book using jsp and store all the information?
To create an address book using JSP, you can create a form to input contact information like name, email, phone number, etc. When the form is submitted, you can handle the data in a servlet and store it in a database like MySQL using JDBC. Then, you can retrieve and display this information in the JSP using Java servlets.
How do you retrieve data from an SQL database so that it can be viewed on a web page using JSP?
import java.sql.*;
public class Lookup { public static voidmain(String[] args) { String dbUrl = "jdbc:odbc:people"; String user = ""; String password = ""; try { // Load the driver (registers itself) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c = DriverManager.getConnection( dbUrl, user, password); Statement s = c.createStatement(); // SQL code: ResultSet r = s.executeQuery( "SELECT FIRST, LAST, EMAIL " + "FROM people.csv people " + "WHERE " + "(LAST='" + args[0] + "') "+ " AND (EMAIL Is Not Null) " + "ORDER BY FIRST"); while(r.next()) { // Capitalization doesn't matter: System.out.println(r.getString("Last") + ", " + r.getString("fIRST") + ": " + r.getString("EMAIL") ); } s.close(); // Also closes ResultSet } catch(Exception e) { e.printStackTrace(); } } } ///:~
In the context of JSP, the Model-View-Controller (MVC) pattern can be implemented by having the JSP act as the View to display data from the Model (usually Java objects) and the Controller can be represented by servlets or Java classes that handle business logic and interact with the Model. The JSP page is responsible for displaying the data provided by the Controller, maintaining a separation of concerns between the presentation (View) and business logic (Controller).
What class is a new servlet usually inherited?
The servlet class created in web applications usually extend the javax.servlet.HttpServlet class. The HttpServlet extends the javax.servlet.GenericServlet. These classes contain the basic features that are required to run a web application.
How do you you refresh your Instagram page?
you cant in the main part when you are looking at your profile, but you can refresh pictures by clicking on them and you can refresh your newsfeed
How do you refresh a page on a tablet?
It depends on what kind of tablet.. For an iPad there is a little arrow going in a circle at the end of the box were it shows the website URL or link. It might be the same with android tablets but i am not sure. It usually looks like an arrow rounded into a circle.
JSP stands for Java Server Pages. JSP is an integral part of any j2ee application. It handles the User Interface (UI) layer of any web based application. It has support to execute java code and also can use HTML and java script. The output of a JSP page is usually viewed in a web browser like Internet Explorer or Mozilla Firefox etc.