Programming Articles - Page 2809 of 3366

How to use a filter in JSP?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

680 Views

Following example shows how to print the client's IP address and the current date time, each time it would access any JSP file. This example will give you a basic understanding of the JSP Filter, but you can write more sophisticated filter applications using the same concept −// Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; // Implements Filter class public class LogFilter implements Filter {    public void init(FilterConfig config) throws ServletException {       // Get init parameter       String testParam = config.getInitParameter("test-param");       //Print the init parameter ... Read More

What are filters in JSP?

George John
Updated on 30-Jul-2019 22:30:25

238 Views

Servlet and JSP Filters are Java classes that can be used in Servlet and JSP Programming for the following purposes To intercept requests from a client before they access a resource at the back end.To manipulate responses from the server before they are sent back to the client.There are various types of filters suggested by the specifications −Authentication FiltersData compression FiltersEncryption FiltersFilters that trigger resource access eventsImage Conversion FiltersLogging and Auditing FiltersMIME-TYPE Chain FiltersTokenizing FiltersXSL/T Filters That Transform XML ContentFilters are deployed in the deployment descriptor file web.xml and then map to either servlet or JSP names or URL patterns in ... Read More

How to read all form parameters in JSP?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

2K+ Views

Following is a generic example which uses getParameterNames() method of HttpServletRequest to read all the available form parameters. This method returns an Enumeration that contains the parameter names in an unspecified order.Once we have an Enumeration, we can loop down the Enumeration in the standard manner, using the hasMoreElements() method to determine when to stop and using the nextElement() method to get each parameter name.           HTTP Header Request Example                        HTTP Header Request Example                 ... Read More

How to pass check boxes data using JSP?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

4K+ Views

Checkboxes are used when more than one option is required to be selected.Following is an example HTML code, CheckBox.htm, for a form with two checkboxes.                     Maths           Physics           Chemistry                     The above code will generate the following result − Maths  Physics  Chemistry Following is main.jsp JSP program to handle the input given by the web browser for the checkbox button.           Reading Checkbox Data               Reading Checkbox Data                Maths Flag:                                  Physics Flag:                                  Chemistry Flag:                               The above program will generate the following result −Reading Checkbox DataMaths Flag :: onPhysics Flag:: nullChemistry Flag:: on

How to read form data using JSP via POST Method?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

3K+ Views

Below is the main.jsp JSP program to handle the input given by web browser using the GET or the POST methods.Infact there is no change in the above JSP because the only way of passing parameters is changed and no binary data is being passed to the JSP program. File handling related concepts will be explained in a separate chapter where we need to read the binary data stream.           Using GET and POST Method to Read Form Data                        Using POST Method to Read ... Read More

What are the standard attributes that should be passed to a custom tag in a JSP page?

Samual Sam
Updated on 30-Jul-2019 22:30:25

85 Views

Consider including the following properties for an attribute −S.No.Property & Purpose1nameThe name element defines the name of an attribute. Each attribute name must be unique for a particular tag.2requiredThis specifies if this attribute is required or is an optional one. It would be false for optional.3rtexprvalueDeclares if a runtime expression value for a tag attribute is valid4typeDefines the Java class-type of this attribute. By default, it is assumed as String5descriptionInformational description can be provided.6fragmentDeclares if this attribute value should be treated as a JspFragment.Following is the example to specify properties related to an attribute −.....           ... Read More

How can I create custom tag in JSP which can accept attribute from parent jsp page?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

237 Views

You can use various attributes along with your custom tags. To accept an attribute value, a custom tag class needs to implement the setter methods, identical to the JavaBean setter methods as shown below −package com.tutorialspoint; import javax.servlet.jsp.tagext.*; import javax.servlet.jsp.*; import java.io.*; public class HelloTag extends SimpleTagSupport {    private String message;    public void setMessage(String msg) {       this.message = msg;    }    StringWriter sw = new StringWriter();    public void doTag()    throws JspException, IOException {       if (message != null) {          /* Use message from attribute ... Read More

I want to create a custom tag in JSP. How to write a custom tag in JSP?

Samual Sam
Updated on 30-Jul-2019 22:30:25

252 Views

A custom tag is a user-defined JSP language element. When a JSP page containing a custom tag is translated into a servlet, the tag is converted to operations on an object called a tag handler. The Web container then invokes those operations when the JSP page's servlet is executed.JSP tag extensions let you create new tags that you can insert directly into a JavaServer Page. The JSP 2.0 specification introduced the Simple Tag Handlers for writing these custom tags.To write a custom tag, you can simply extend the SimpleTagSupport class and override the doTag() method, where you can place your ... Read More

Please share one example of using taglib directive in JSP

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

112 Views

The JavaServer Pages API allow you to define custom JSP tags that look like HTML or XML tags and a tag library is a set of user-defined tags that implement custom behavior.The taglib directive declares that your JSP page uses a set of custom tags, identifies the location of the library, and provides means for identifying the custom tags in your JSP page.The taglib directive follows the syntax given below −Where, the uri attribute value resolves to a location the container understands and the prefix attribute informs a container what bits of markup are custom actions.You can write the XML ... Read More

How to read form data using JSP via GET Method?

George John
Updated on 30-Jul-2019 22:30:25

506 Views

Following is an example that passes two values using the HTML FORM and the submit button. We are going to use the same JSP main.jsp to handle this input.                    First Name:                    Last Name:                     Keep this HTML in a file Hello.htm and put it in /webapps/ROOT directory. When you would access http://localhost:8080/Hello.htm, you will receive the following output.First Name: Last Name:   Try to enter the First Name and ... Read More

Advertisements