answersLogoWhite

0

JSP and Servlets

JSP (JavaServer Pages) are Java programs encoded within webpages that research and generate pertinent results. Servlets, on the other hand, are objects (programs) that handle requests from users and provide results based on these requests.

500 Questions

What is difference between servlets and java server pages?

User Avatar

Asked by Wiki User

SERVLETS

JSP

1. Servlet is a java class.

2. Servlet is a single instance multiple thread web application, In which HTML code can be included in java code.

3. In servlets the presentation logic and the B.logic is tightly coupled.

4. For every modification done in servlet program, we need to recompile and reload the application.

5. In servlets implicit objects are not available.

6. Servlets are supported to HTTP, FTP, and SMTP protocols.

7. Sevlets are need Deployment Descriptor file (web.xml)

1. Jsp is a file.

2. In jsp java code can be included in HTML code by using special tags.

3. In jsp's the presentation logic and B.logic are separated by defining the java beans.

4. If any modifications done in jsp's without recompiling and reloading , the modifications are reflected.

5. In jsp's implicit objects are available which is we can implement directly into jsp pages.

6. Jsp are supported to HTTP protocol only.

7. No need of Deployment Descriptor file (web.xml)

rajus_1219@yahoo.co.in

What are the servlet config methods?

User Avatar

Asked by Wiki User

Methods in the Servlet Context

Apart from setting and getting custom attributes used for our application, the context also contains various methods that we can use to retrieve specific information about the application and other aspects. They are:

• getAttributeNames() - Returns an Enumeration object containing the attribute names available within this servlet context.

• getContext(String uripath) - Returns a ServletContext object that corresponds to a specified URL on the server.

• getInitParameter(String name) - Returns a string containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

• getInitParameterNames() - Returns the names of the context's initialization parameters as an Enumeration of string objects, or an empty Enumeration if the context has no initialization parameters.

• getMajorVersion() - Returns the major version as an int of the Java Servlet API that this Servlet Container supports.

• getMimeType(java.lang.String file) - Returns the MIME type as a string of the specified file, or null if the MIME type is not known.

• getMinorVersion() - Returns the minor version as an int of the Servlet API that this Servlet Container supports.

• getNamedDispatcher(String name) Returns a RequestDispatcher object that acts as a wrapper for the named servlet.

• getRealPath(String path) - Returns a string containing the real path for a given virtual path.

• getRequestDispatcher(String path) Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.

• getResource(String path) - Returns a URL to the resource that is mapped to a specified path.

• getResourceAsStream(String path) - Returns the resource located at the named path as an InputStream object.

• getServerInfo() Returns the name and version as a String of the Servlet Container on which the servlet is running.

When do you use JSPs as opposed to Servlets?

User Avatar

Asked by Wiki User

JSPs and Servlets can be used interchangeably for the most part. In fact, when a JSP is compiled, it is actually turned into a servlet! That being said, there are some guidelines for using servlets over JSPs or vice versa. Here are a couple of examples, but by no means a complete list: Typically, you would use a JSP to display dynamic data, or a form. A Servlet is usually what you would want to use to process a post or a get, especially considering the method that is called when you call a servlet (either doGet or doPost). For more information on this, here is a good article on Servlet and JSP Best Practices: http:/java.sun.com/developer/technicalArticles/javaserverpages/servlets_jsp

What are the advantages and disadvantages of servlet?

User Avatar

Asked by Wiki User

Servlets are an integral part of any J2EE Web application. The key benefits of using Servlets in our web applications are:

a. They are faster than CGI scripts because each CGI script produces an entirely new process that takes a lot of time to execute, whereas a servlet creates only a new thread.

b. Servlet API is standard and available easily on the internet (like JSPs)

c. Servlets have the advantages like ease of development & platform independence (like Java)

d. They can access all the J2SE and J2EE APIs

e. Can take the full advantage & capabilities of the Java programming langauge

As you can see, there are numerous advantages of using the Servlet & JSP technologies. This is exactly why numerous organizations use them as a staple part of their J2EE application development work.

The Disadvantage would be that Servlets are a little difficult to learn and use.

Is it necessary to learn advanced java for JSP?

User Avatar

Asked by Wiki User

It is a good to know item. It is not mandatory or necessary. Basic knowledge of core Java is enough to learn JSP and Servlets.

Set and get session attributes syntax in servlets and java script?

User Avatar

Asked by Wiki User

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 java servlet chaining?

User Avatar

Asked by Wiki User

Servlet Chaining means the output of one servlet act as a input to another servlet. Servlet Aliasing allows us to invoke more than one servlet in sequence when the URL is opened with a common servlet alias. The output from first Servlet is sent as input to other Servlet and so on. The Output from the last Servlet is sent back to the browser. The entire process is called Servlet Chaining.

How do you refresh a page?

User Avatar

Asked by Wiki User

Click on the refresh button which is mostly located next to the address bar on the top of the page and looks like a blue arrow, mostly 2 arrows making a circle. to make it easier, you can also press the 'F5' button on the top of your keyboard.

Where you can download java servlet development kit2.0?

User Avatar

Asked by Wiki User

There is no specific/separate servlet development kit. Servlets can be developed and compiled using the standard JDK and JRE.

The only difference being the fact that - to run them you need a web server

How do you transfer values from javascript to JSP?

User Avatar

Asked by Wiki User

You can set the value in the hidden form fields using javascript and access the form fields in JSP

What is the Expansion for JSP?

User Avatar

Asked by Wiki User

JSP stands for Java Server Pages. They are used in Java Enterprise applications that are created to be used on web pages. The JSP page acts as the user interface for the enterprise application.

Which is the website for jsp tutorials?

User Avatar

Asked by Wiki User

There are many websites for JSP Tutorials. Just google with text as "JSP Tutorials" or click on the related links in this answer...

What is the difference between asp and servlet?

User Avatar

Asked by Wiki User

ASP is a server side technology which enables a developer to combine both HTML & scripting language in the same page.

servlets are server side programs written in java.It is platform independent

What are the JSP lifecycle methods?

User Avatar

Asked by Wiki User

The 3 life cycle methods in a JSP page are:

  • jspInit() - Called when the JSP page is initialized
  • jspService() - Called everytime a request/response is received/submitted
  • jspDestroy() - Called when the JSP is no longer required

How do you get ServletContext object in EJB - 38k?

User Avatar

Asked by Wiki User

get servlet context path from EJB

What is a java servlet?

User Avatar

Asked by Wiki User

A Servlet is a Java class that is the heart & brain of web applications.

Web applications are applications that are viewed via the browser.

Let me explain with an example.

You are now in wikianswers website. You have a bunch of links on the left side of this page. When you click on any of them you can see that the page goes somewhere and then reloads with fresh content.

Once you click the system goes to the servlet. Based on the link you clicked the servlet would decide which page to open and then it will fetch the necessary information that would be needed for the page.

Difference between JSP and CGI programming?

User Avatar

Asked by Wiki User

JSP stands for JAVA SERVER PAGES, where as CGI stands for COMMON GATEWAY INTERFACE.

In CGI, whenever a multiple requests of the same dynamic web page is made by the client to the server, a new process is cerated of the corrosponding CGI program, for each an every request generated as such..

this is not the case in JSP..

in JSP, when the first request is made for a dynamic web page..its corrosponding class file an hence the servlet is then cached in the memorey, and hence new threads are generated for the futher requests made, saving resources..

What are the Implicit object in JSP?

User Avatar

Asked by Wiki User

The implicit objects in a JSP page are:

  • request
  • response
  • pageContext
  • session
  • application
  • out
  • config
  • page

What is servlet mapping?

User Avatar

Asked by Wiki User

A Servlet Mapping is a directive in the web.xml that tells the Servlet Container which class to use when a particular Servlet is called. A Servlet is a class within your Java Web Application. Let's say you have a servlet called MyServlet in the com.example.servlet package. You would need to have a Servlet Mapping pointing the path "/MyServlet" to the "com.example.servlet.MyServlet" class. Without the servlet mapping, you would not be able to invoke your servlet because the Servlet container would not know where it is. JSPs are different - they do not need mappings like this. JSPs exist within the WebRoot of the application, so they are always available. Servlets exist in the WEB-INF\Classes directory once your application is deployed.

Difference between temporary servlet and permanent servlet?

User Avatar

Asked by Wiki User

A temporary servlet is started when a request arrives and shut down after the response is generated. A permanent servlet is loaded when the server is started and lives until the server is shut down.

* This is useful when startup costs are high, such as a servlet that establishes a connection to a database.

* Also useful for permanent serverside service, such as an RMI server.

* Provides faster response to client requests when this is crucial. Being temporary or permanent is part of the server configuration.

What is a session What are the different ways of session tracking in servlet programming?

User Avatar

Asked by SantanuPakira

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.