Home Tutorialhelp Comment A very simple example for redirect

 
 

Comment

Awani Gupta
A very simple example for redirect,
August 14, 2007 at 6:11 PM

import java.io.*;
import javax.servlet.*;
import java.util.*;
import javax.servlet.http.*;

/**
* @version 1.0
* @author
*/
public class Unaware extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String type = request.getParameter("TypeValue");
String name = request.getParameter("Name");
if (type.equals("First"))
{
pw.println("This is the request handled by the 1st servlet");
pw.println("<html><body> Hello : "+ name + "</body></html>");

}
else
{
response.sendRedirect("/HelloServlet/Aware");
}
}


}
------------------------------------------------
------------------------------------------------

import java.io.*;
import javax.servlet.*;
import java.util.*;
import javax.servlet.http.*;

/**
* @version 1.0
* @author
*/
public class Aware extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String name1= request.getParameter("Name");
pw.println("This is the request handled by the 2nd servlet");
pw.println("<html><body> Hello : User" + name1+ "</body></html>");

}

}
-----------------------------------------------
-----------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<TITLE>Directive.html</TITLE>
</HEAD>
<BODY>
<FORM action="/HelloServlet/Unaware"><SELECT name="TypeValue">
<OPTION>First</OPTION>
<OPTION>Second</OPTION>
<OPTION>Third</OPTION>
</SELECT><BR>
<BR>
<INPUT type="text" name="Name" size="20">
<BR>
<INPUT type="submit" name="Submit" value="Submit">
<BR>
</FORM>
</BODY>
</HTML>
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
JSP Tutorials

Jsp redirect
Jsp redirect          In this section, you will learn how to redirect a page in JSP. You can see in the given example that we have used the method 

Struts Questions

redirect with tiles - Struts
redirect with tiles  I have definition with three pages. I have link in page left when i click it is page Body change. Help me! Thanks very much... in struts 2. And i want redirect to other definition tag by url tag. Please help me 

Struts 2 Tutorials

Struts 2 Redirect Action
Struts 2 Redirect Action       In this section, you will get familiar with struts 2 Redirect action and learn to use it in the struts 2 application. Redirect After Post: This post 

Java Technology Tutorials

Java Redirect output to file
Java Redirect output to file This section illustrates you how to redirect... to redirect the run-time exceptions and SOPs (System.out.println) to a file... to the file. In the given example, we have set the output stream of System 

JSP Servlet Questions

send redirect in JSP - JSP-Servlet
send redirect in JSP   How can I include a message i.e "redirected to this page because blah blah" in the send redirect page?  Hi friend, Please specify your problem the message print on the redirect to the next 

HTML Questions

How to redirect from a HTML page?
/ValidUser"); Here is an example of Send Redirect in Servlet. Thanks...How to redirect from a HTML page?  Hi, Is it possible to redirect from HTML page to another page on the net? I have one page and I want to redirect 

Struts 2 Tutorials

Redirect Action Result Example
Redirect Action Result Example The Result uses the ActionMapper of the ActionMapperFactory for redirecting the URL to the specified action. To redirect...;/jsp/home.jsp</result> </action> An example of Redirect Action 

Struts 2 Tutorials

Redirect Result Example
Redirect Result Example The Redirect Result makes a new call to the resources...;redirect">error Page</result> </action> An Example of Redirect... (?id=userId). To use Redirect Result in your application you need to do following 

Struts Questions

Redirect page
Redirect page  In this code redirect tag is not work, so please help me ,how to redirect page in Tiles With JSTL . <%@ taglib prefix="tiles"uri="http://jakarta.apache.org/struts/tags-tiles" %> <%@ taglib prefix="c"uri 

Programming Tutorials

ZF Page Redirect
Redirect to another page using submit button, in ZF: It is one of the most common activity in a web application to redirect one web page to another web page. We will learn how to redirect page in Zend Framework form. As we have 

Struts Questions

C:Redirect Tag - Struts
C:Redirect Tag  I am trying to use the jstl c:redirect tag... to the true start page of the web application. In performing the redirect, I want... information will have already been initialized. Is this possible with the c:redirect 

HTML Questions

Redirect Entire Frame
Redirect Entire Frame  Hello All:) I ve 2 frames in a html file. Say..., it will redirect in the trailer part. Before redirecting the page i had redirected to some.... Any one have idea how i can redirect the entire header and trailer? What i can do 

JSTL

Using tag <c:redirect> of Core JSTL tags
      In this example we have used Core JSTL tag <c:redirect> that is used to redirect the page to given url, here...://java.sun.com/jsp/jstl/core" %> redirect_CoreJstl.jsp < 

JSP Servlet Questions

How to use filter to redirect to login page after session timeout.
How to use filter to redirect to login page after session timeout.  ... then automatically it should redirect to login page from where user has... not have the idea . will you plz give me the example for this task . will always 

JSP Servlet Questions

How to use filter to redirect to login page after session timeout.
How to use filter to redirect to login page after session timeout.  ... then automatically it should redirect to login page from where user has... not have the idea . will you plz give me the example for this task . will always 

JSP Servlet Questions

How to use filter to redirect to login page after session timeout
How to use filter to redirect to login page after session timeout  ... then automatically it should redirect to login page from where user has to login again... . will you plz give me the example for this task . will always be gratefull 

JSP Servlet Questions

redirect to multiple links from servlet
redirect to multiple links from servlet  hello , In my servlet page... the output in browser,i need to redirect to another link like the above line. i want redirect to multiple links simultaneously. anyone help me out 

Java Beginners

how to redirect jsp page to extjs
how to redirect jsp page to extjs   my requirement is redirect jsp page to extjs form. Am using spring mvc...my welcome page is index.jsp from that index.jsp i need to redirect to extjs. can any one help me in this thanks 

JSP Servlet Questions

Redirect from servlet to servlet
Redirect from servlet to servlet  I want to insert data from Text box to oracle database ,so in my HTML where there are text box (and 3 Buttons-New ,Update and save)so when i click any of three buttons it takes me 

JDBC Questions

Redirect the log used by DriverManager and JDBC driver
Redirect the log used by DriverManager and JDBC driver  How can I get or redirect the log used by DriverManager and JDBC drivers 

Servlet Interview Questions

servlet redirect problem help needed
servlet redirect problem help needed  package p; import java.io.IOException; import javax.servlet.RequestDispatcher; import... the counter executes the line re.forward(req, resp);..it it redirect to jsp 

Servlet Interview Questions

servlet redirect problem help needed
servlet redirect problem help needed  package p; import java.io.IOException; import javax.servlet.RequestDispatcher; import... the counter executes the line re.forward(req, resp);..it it redirect to jsp 

JSP Servlet Questions

Making 301 redirection by using <c:redirect>
Making 301 redirection by using   How can i set the status as 301 when using tag? When i use , I am able to redirect to the desired URL (here, Google page) but I get 302 as the status of redirect. I need this status as 301. Any 

Java Server Faces Questions

Redirect to same jsp page on successful login
Redirect to same jsp page on successful login  Hi, I have an application where on successful login, the redirect should happen to same page with a session created for the user. On login, i have some dropdowns which are populated 

Java Server Faces

Using redirect element & wild card
Using redirect element & wild card          <redirect/>... is generated by the new view using redirect response rather than rendering the response 

Servlets

Send Redirect in Servlet
Send Redirect in Servlet     ... Redirect whenever the client makes any request it goes to the container... is unaware of the processing.  In this example we are going to make one html 

PHP Questions

How many ways I can redirect a PHP page?
How many ways I can redirect a PHP page?   How many ways I can redirect a PHP page 

JSP-Tutorials

Redirect to Google Search JSP
Redirect to Google Search JSP This tutorial explains you how can you crate.... To create a Google search on the web page we will use JSP. Example Here we will give an example of how to provide a google search on your web page 

JSP Servlet Questions

Servlet Response Send Redirect - JSP-Servlet
 

Java Beginners

validating username and password in servlet and redirect to login page with error message if not valid
validating username and password in servlet and redirect to login page with error message if not valid  hi i want to validate my login page username and password in my servlet against database and if not valid want to display 

Servlets-Tutorials

Sendredirect In Servlet
the buffer. Example Here we will give a simple example which will demonstrate... from one resource to another. In this example we will create a simple Servlet...() method. sendredirect() method is used to redirect the control to the different 

JSP Servlet Questions

jsp and servlets
the request submitted from browser and process the data and redirect it to JSP 

Java Interview Questions

servlets
servlets  why we require wrappers in servlets? what are its uses.../response. For e.g. compression, encryption, XSLT etc. Here is an example: http://www.roseindia.net/servlets/response-filte.shtml 

Servlet Interview Questions

servlets
servlets  what are different authentication options available in servlets   There are four ways of authentication:- HTTP basic... send by theclient. The password is sent using simple base64 encoding but it?s 

General

Very simple `Hello world' java program that prints HelloWorld
Hello World Java Simple Java Program for beginners... to develop robust applications. Writing a simple Hello World program is stepwise step. This short example shows how to write first java application and compile 

HTML

Simple HTML example
Simple HTML example In this section we will give you very simple example of a HTML page. After reading this page you should be able to create simple HTML... pages. Creating Simple HTML page Here is simple example of HTML page that displays 

Servlet Interview Questions

servlets
; Please visit the following links: Logging Filter Servlet Example   Response Filter Servlet Example 

Servlet Interview Questions

servlets
. The Server Side Includes is a simple interpreted server side scripting used in HTML 

Servlets

Send Redirect in Servlet
Send Redirect in Servlet       When we want that someone else should handle the response of our servlet, then there we should use sendRedirect() method.  In send Redirect 

Design concepts & design patterns Questions

How to design a simple note book
How to design a simple note book In this example you will learn to make simple note book, It is a very simple so follow this tutorial. New File: Create a new file with appropriate size. Rectangle Shape 

Java Beginners

Simple FTP upload in Java
Simple FTP upload in Java  How to write a program for Simple FTP upload in Java? Any code example of Simple FTP upload in Java will be very helpful for me. Thanks 

Java Beginners

servlets - Java Beginners
or application servers only.Using servlets we can't generate presentation very effectively because html code is hard coded in servlets,so it is very difficult...servlets  what is the difference b/w servlets and JSP, what servlets 

Servlets-Tutorials

Java Servlet : SendRedirect
Java Servlet : SendRedirect In this tutorial, you will learn how to redirect.... SendRedirect() : Response provide method sendRedirect() which sends a redirect response to the client using the given redirect location. You can specify relative 

JSP Servlet Questions

Simple problem Very Urgent - JSP-Servlet
Simple problem Very Urgent  Respected SDir/Madam, I am R.ragavendran.. Thanks for your superb reply. I got the coding. But I find a simple problem which i hava tried my level best to solve. A pop up window is opening 

JSP Servlet Questions

Simple Program Very Urgent.. - JSP-Servlet
Simple Program Very Urgent..  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your superb reply. I find a simple problem which i have tried my level best to solve.In the output, the text box is receiving some other value 

Java Beginners

Java simple reference source - Java Beginners
Java simple reference source  Hi, please could you recommend me a Java simple reference source (on line or e-book) where I could quickly find the stuff? For example list of operetors , list of loops + usage, list if ArrayList 

Spring Framework

UrlFileNameViewController Example
UrlFileNameViewController Example       UrlFileNameViewController Example in Spring 2.5 Web MVC... and redirect to some resource then user used  UrlFilenameViewController 

General

RequestDispatcher vs sendRedirect
or a redirect operation at the end of processing a request. Here are the basic differences... to resources (servlets or JSP's) of the same ServletContext. You can also 

Hibernate Questions

Simple Example of Hibernate 4
Simple Example of Hibernate 4  Hi, As a new comer in the Hibernate programming, I want simple program of Hibernate to learn the basic concepts... Simple Example More Tutorials for a beginner: Hibernate Tutorials Home page 

Java Tips and Examples

Switch Statement example in Java
Switch Statement example in Java        This is very simple Java program... also provides you an example with complete java source code for understanding 

Srping 2.5

Simple Form Controller Example
Example of using Simple Form Controller Page 2 In this page we will see the next steps necessary to run the example code.  Here... it at Example of using Simple Form Controller Step 7: Now we 

Spring Framework

Spring Bean Example, Spring Bean Creation
: Spring is simple Download this example code... Object) in the IoC container. Here in this tutorial you will see at first a simple...;String mesg = "Spring is simple";    

Enterprise Java

JSF 2.0 Simple Example
This section contain simple Hello World Example using JSF 2.0. 

Programming Tutorials

Simple Ajax Example
 

Servlets

Advantages of Servlets over CGI
, programs written in java are slow. But the java servlets runs very fast... handling etc. Servlets inherits all these features and emerged as a very... Advantages of Servlets over CGI      

JavaScript Tutorial

PHP Redirection Redirecting URL Tutorial, PHP Redirecting URL
way. For example any web programmer should know about the Content-Type header... in the HEAD part of the HTML page. Example of the HTML page with redirection...;Redirect page</H1> </BODY> </HTML> The third method is about 

Servlet Interview Questions

Servlets Programming
Servlets Programming  Hi this is tanu, This is a code for knowing...; import javax.servlet.http.HttpServletResponse; //In this example we are going... visit the following links: http://www.roseindia.net/servlets 

Free Programming books

Servlets Books
Platform, by Dustin R. Callaway  Java Servlets by Example, by Alan R... Servlets Books        ... Courses Looking for short hands-on training classes on servlets 

Ajax Examples

Simple Ajax Example, Developing Simple Ajax application
Simple Ajax Example       Simple Ajax Example In this tutorial we are going to develop a very simple Ajax Example. This simple Ajax example code will help you in understanding the core 

Hibernate Questions

Hibernate Simple Program Using Java Application with Eclipse
Hibernate Simple Program Using Java Application with Eclipse  How to write Hibernate Simple Program Using Java Application with Eclipse? I wish to learn Hibernate using very popular Eclipse IDE. Share me the best tutorial link 

Enterprise Java

JSF 1.2 Simple Example
This section contains simple example using JSF 1.2. This is a startup tutorial for JSF beginners 

J2EE

Simple Line Canvas Example
Simple Line Canvas Example       This is a simple example of drawing lines using canvas class in J2ME. In this example we are creating three different lines at different 

Programming Tutorials

The Simple API for XML (SAX) APIs
The Simple API for XML (SAX) APIs   ... doing more sophisticated SAX processing, for example, to process... that make it easier to use SAX -- for example, by defining a default handler 

JSP-Tutorials

JSP Simple Examples
: out> For Simple Calculation and Output In this example we have used... all know that it can be done very easily in the servlets and jsp... in the ServletContext.  ServletContext is shared by all servlets 

Java-Tutorials

Array Relocation Example
Description: This example demonstrate the Array Relocation where value of any index can be change. Code: import java.util.Arrays; public class ArrayReallocation {    

Java Beginners

Java Servlets
Java Servlets  If the binary data is posted by both doGet and doPost then which one is efficient?Please give me some example by using both doGet and doPost. Thanks in Advance   The doPost method is more efficient 

Hibernate-Tutorials

Hibernate 4 Simple Example
Hibernate 4 Simple Example This section contains a simple Hibernate 4 example... in this example. In Hibernate 4, buildSessionFactory( ) is deprecated. This example contains code which you can use in spite of buildSessionFactory 

JSP Tutorials

Developing Simple Struts Tiles Application
Developing Simple Struts Tiles Application  ... will show you how to develop simple Struts Tiles Application. You will learn how to setup the Struts Tiles and create example page with it. What is Struts 

Spring Framework Questions

No complete codes for Simple Form Controlle Example
No complete codes for Simple Form Controlle Example  No complete codes 

Ajax Questions

JSP and AJAX- very urgent - Ajax
JSP and AJAX- very urgent  Respected Sir/Madam, I am Ragavendran.. I have a simple doubt.. At present, I am in a module of the project... Plz its very very Urgent.. Regards, Ragavendran 

General

Simple Date example
Simple Date example       In this section we have presented a simple Date example... is the example code of SimpleDate.java as follows: SimpleDate.java import 

PHP Questions

simple class in php
simple class in php  example of simple class in PHP 

JSP Servlet Questions

Program Very Urgent.. - JSP-Servlet
Program Very Urgent..  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your superb reply. I got the link you sent. But I find a simple problem which i hava tried my level best to solve.In the output, the text box 

General

Accessing Database from servlets through JDBC!
runs very fast. These are due to the way servlets run on web server.... But in case of servlets initialization takes place very first time... Java Servlets - Downloading and Installation    

WebSevices Questions

Regarding Simple Web service example - WebSevices
Regarding Simple Web service example  hi i am trying to follow the simple web service example in the tutorials and it develops the application in Netbeans IDE using the GlassFish Server . however when i did the same 

JSP Servlet Questions

Servlets errors in same page.
Servlets errors in same page.  How do I display errors list in the same page where a form field exists using servlets...........i.e. without using JSP? Please explain with a simple username password program 

General

Simple Date Format Example
Following is a simple date format example made using Format class. We have uses a pattern of special characters to date and time format. In this example... is a simple Date Format Example: import java.text.*; import java.util.*; public 

JSP Servlet Questions

servlets - JSP-Servlet
servlets  I want to write a simple program on servlet context attribute listener.  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/ServletContextAttributeListener.shtml Hope 

JSP Servlet Questions

servlets - JSP-Servlet
servlets  i want to write a simple program on servlet context listener.  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/ServletContextListener-example.shtml Hope 

JDBC Questions

MYSQL and SERVLETS - JDBC
.How I can do using servlets   Hi friend, For developing a simple... servlets .I do not know that how to combine these two programs into a single...://www.roseindia.net/servlets/web-application.shtml Thanks 

JSP Servlet Questions

servlets execution - JSP-Servlet
servlets execution  the xml file is web.xml file in which the servlet... will very help to you. Please visit for more information. http://www.roseindia.net/servlets/ Thanks. Amardeep 

JSP Servlet Questions

servlets execution - JSP-Servlet
servlets execution  hi friends, i wanted to know how to compile... file.but i dont know this.plzzzzzzzzzz do help me as its very urgent. ..., To visit this link for solving the problem: http://www.roseindia.net/servlets 

Java Beginners

servlets - Java Beginners
servlets   I am doing small project in java on servlets. I want to generate reports on webpage ,how is it possible and what is the difference between dynamic pages & reports ? tell me very urgent pls,pls 

Java Beginners

Simple program to combine all html,ajax,java,servlets,jsp,json - Java Beginners
Simple program to combine all html,ajax,java,servlets,jsp,json  Hi, I learned Java,servlets,jsp basics, html, ajax, json and css. I want to do... to design a simple html page with a input field and submit button. I tried to do 

General

Simple date formatter example
Simple date formatter example       In this section of simple date formatter example we... is the full example code of SimpleFormatDate.java as follows: SimpleFormatDate.java 

JDBC Questions

Servlets and Jsp - JDBC
Servlets and Jsp  Sir I have seven fields like Matcode ,Matname...,Min value ,Otherfields has to be set as zero.How can i do this in servlets and Jsp.It is very urgent ,please send the program 

EJB Tools

DEVELOPING & DEPLOYING A PACKAGED EJB
' is very important in Enterprise Java. Compiling and Deploying such packaged servlets... the concepts with a simple and practical example. There have been a number... will be simple to follow and to execute. For example, it is absolutely essential to use 

Servlet Interview Questions

servlets
servlets  what is the duties of response object in servlets 

Servlet Interview Questions

servlets
servlets  why we are using servlets 

JSP Servlet Questions

simple java search engine
simple java search engine  i have already downloaded the project simple java search engine.but i am not able to run it.can anyone help me.i have.... ABSTRACT Title : Simple Search Engine System Specification: The system on which 

Servlet Interview Questions

servlets
what are advantages of servlets  what are advantages of servlets   Please visit the following link: Advantages Of Servlets 

Java Beginners

simple calculator - Java Beginners
simple calculator  how can i create a simple calculator using java codes?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/swing/calculator-in-swing.shtml Thanks 

JDBC Questions

servlets And Jsp - JDBC
servlets And Jsp  Sir, I did updation,deletion and addition, I had taken the program from roseindia web site.http://www.roseindia.net/servlets... me.It is very urgent .I tried but i couldn get it properly.  Hi 

JSP Servlet Questions

servlets and jsp - JSP-Servlet
servlets and jsp  HELLO GOOD MORNING, PROCEDURE:HOW TO RUN A SERVLET AND JSP IN COMMANDPROMPT AND ALSO IN NETBEANS IDE6.0,IT'S VERY URGENT FOR ME,IN ADVANCE THANK U VERY MUCH.   TO Run Servlets in Compand 

J2EE

@WebServlet Login and Logout Example
@WebServlet Login and Logout Example In this tutorial I am giving a very simple example which will demonstrate how you can create a login page, how can you.... Example : login1.html <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 

Hibernate Questions

Simple application using hibernate
Simple application using hibernate  Hi, How to write a simple... and testing example program Thanks   Hi, I have given the links of the tutorial you will like to learn for creating the simple application using 

JSP Servlet Questions

Servlets - JSP-Servlet
Servlets  Hello Sir, can you give me an example of a serve let program which connects to Microsoft sql server and retrieves data from it and display... visit the following link: http://www.roseindia.net/servlets 

Java Beginners

Servlets - Java Beginners
Servlets  Hi, How can i run the servlet programon my system? I wrote the code in java.(I've taken the Helloworld program as example program... for more information, http://www.roseindia.net/servlets/ Thanks Amardeep 

JSP Servlet Questions

Servlets
Servlets  How to edit and delete a row from the existing table in servlets 

Servlet Interview Questions

servlets
servlets  How do you communicate between the servlets?   We can communicate between servlets by using RequestDespatcher interface and servlet chaining 

Advertisements Advertisements
 

 

 

DMCA.com