Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Redirect from servlet to servlet

Have Programming Question? Ask it here!
 
 
 


Ajay Kumar
Redirect from servlet to servlet
0 Answer(s)      10 months ago
Posted in : JSP-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 to redirectServlet , and from this servlet I want to again forward my page to insertServlet(i.e When I click NEW Button) ,but I am getting 404 error . May be my logic is wrong or wex.xml needs to be mapped properly . Can anyone help please Its urgent.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>AcerLink</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

     <servlet>

    <display-name>redirectServlet</display-name>
    <servlet-name>redirectServlet</servlet-name>
    <servlet-class>redirectServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>redirectServlet</servlet-name>
    <url-pattern>/redirectServlet</url-pattern>
  </servlet-mapping> 

  <servlet>
    <description></description>
    <display-name>insertServlet</display-name>
    <servlet-name>insertServlet</servlet-name>
    <servlet-class>insertServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>insertServlet</servlet-name>
    <url-pattern>/insertServlet</url-pattern>
  </servlet-mapping>
</web-app>

redirectServlet

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**

 * Servlet implementation class redirectServlet

 */

public class redirectServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;


    /**

     * @see HttpServlet#HttpServlet()

     */

    public redirectServlet() {

        super();

        // TODO Auto-generated constructor stub

    }


    /**

     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

     */

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // TODO Auto-generated method stub


    }

    /**

     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

     */

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // TODO Auto-generated method stub

        if (request.getParameter("NEW") != null) {


            response.sendRedirect("/insertServlet");


            return ;



        } else if (request.getParameter("UPDATE") != null) {

            request.getRequestDispatcher("/redirectServlet").forward(request, response);




        }  else if (request.getParameter("SAVE") != null) {

            request.getRequestDispatcher("save.jsp").forward(request, response);

        }

    }

}

insertServlet

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class insertServlet
 */
public class insertServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public insertServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter out = response.getWriter();
        PrintWriter pwinsert = response.getWriter();
//      PrintWriter pwdelete = res.getWriter(); 

        Connection con = null;
        PreparedStatement ps = null;
       // ResultSet rs = null;
       // Statement st = null;

        String appl=request.getParameter("app");
        String sel=request.getParameter("second");
        String url= request.getParameter("link");

        try {
            Class.forName("oracle.jdbc.OracleDriver");
        }
        catch(ClassNotFoundException ex)    {
            System.out.println("driver not loaded");
            System.exit(0); 
        } 
        String URL = "jdbc:oracle:thin:SCOTT/tiger@computer_1:1521:orcl";
        try {
            con = DriverManager.getConnection(URL); 

            if(request.getParameter("choise")==null)    {
                ps = con.prepareStatement("INSERT into TEST_LINKS (ID,APPLICATION,ENTITY,URL) VALUES(TEST_LI.nextval,?,?,?)"); 
                ps.setString(1,appl);
                ps.setString(2,sel); 
                ps.setString(3,url); 

                int i = ps.executeUpdate(); 
                pwinsert.println(i); 

                if(i!=0)    { 
                    pwinsert.println("Your data has been stored in the database"); 
                } 
                else    { 
                    pwinsert.println("Your data could not be stored in the database"); 
                } 
            }
        } 
        catch(Exception e)  {
            pwinsert.println(e.getMessage());
        } 

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Redirect from servlet to servlet
Redirect from servlet to servlet  I want to insert data from Text box... to redirectServlet , and from this servlet I want to again forward my page to insertServlet(i.e...; <servlet-name>redirectServlet</servlet-name> <servlet
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
Advertisements
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatc‚?¶ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatc‚?¶ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
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
Servlet Response Send Redirect - JSP-Servlet
from the visit table. Can you please show me how I can pass more than one column value to the next jsp? 2. I have a servlet that saves patient data from...Servlet Response Send Redirect  Hi, Thank you for your previous
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
Calling servlet from servlet .
Calling servlet from servlet .  How to call a servlet from another servlet in Java?   You can call another servlet by using... ServletException, IOException { System.out.println("Calling another servlet by using
Send Redirect in Servlet
Send Redirect in Servlet     ... entered by the user is correct then the servlet will redirect the request... of our servlet, then there we should use sendRedirect() method.  In send
calling servlet from jsp
calling servlet from jsp  how to call a servlet from jsp
Send Redirect in Servlet
Send Redirect in Servlet      ... servlet, then there we should use sendRedirect() method.  In send Redirect... decides whether the concerned servlet can handle the request or not.  
How to redirect from a HTML page?
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.../ValidUser"); Here is an example of Send Redirect in Servlet. Thanks
Navigate from jsp to servlet - JSP-Servlet
Navigate from jsp to servlet   Hi Friends, Sample code for Navigating a page from jsp to servlet. Thanks
how to fetch data from servlet ????
how to fetch data from servlet ????  how to fetch data from servlet
ArrayList from JSP to Servlet - JSP-Servlet
ArrayList from JSP to Servlet  Hi, I have an arraylist declared in a scriplet in a jsp page. how can i access the arraylist in a servlet which...)); %> How can I access this arraylist in a servlet. How
servlet
servlet  how to interact with a servlet from a swing program
Servlet
Servlet  What is Servlet
Call servlet from javascript - JSP-Servlet
Call servlet from javascript  Hi in my application i have jsp that designs view, javascript for validation and servlet that perform business logic... screen when the user clicks submit button i have to pass this column values from
Getting data from servlet into javascript
Getting data from servlet into javascript  How do i get json data from my servlet on to a variable in javascript n bind the data to display onto sigma grid.Has anyone Idea how to do
write to file from servlet - JSP-Servlet
write to file from servlet  Hi, I have a jsp file where I input data and retrive data through servlet. However; when I edit data it is not showing... and POST methods. * @param request servlet request * @param response
Servlet
Servlet  how to navigate one servlet page to another servlet page
Sendredirect In Servlet
from one resource to another. In this example we will create a simple Servlet...Sendredirect In Servlet In this section you will read about the sendredirect() method. sendredirect() method is used to redirect the control to the different
servlet
servlet  can i stoar record in variable which selected from table in servlet
calling servlet from JS and return response from servlet to JS
calling servlet from JS and return response from servlet to JS  hello...) which inturn calls a servlet(myServlet).servlet performs some DB related task.now i want this servlet(myServlet) to return a url(eg. pages/file.jsp
servlet session - JSP-Servlet
servlet session  hi, im working on a real estate web site.....n im stucked....actually if a user login from any page on web site suppose hi calls login servlet fromabout us page now i want the servlet to redirect me
servlet
servlet  How many times the servlet is accessed
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  how to read a file from different folder using filereader in servlet   Hello Friend, Please visit the following link: http://www.roseindia.net/servlets/servlet-read-file.shtml Here you will get an useful
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  i want to create a login page with servlet using database mysql? only in servlet not in jsp plzz help me out
Servlet
override Service method in the servlet when you extend GenericServlet to create servlet as it is mandatory to override it. But, when you extend HttpServlet to create a servlet then you can't override service method as there is a need to override
servlet
servlet file which prints out the user's inputs. I need to use the post method to pass the data from html to the java servlet and also use both doGet and doPost methods in the servlet. I think, but unfortunately I have a terrible teacher
Servlet
Servlet  What must be implemented by all Servlets?    The Servlet Interface must be implemented by all servlets
servlet
servlet  i want a program for counting the no of times the servlet has been invoked
servlet
servlet  how to create a login form using servlet using submit,edit delete button
servlet
servlet  dear sir servlet and html not run on eclips plz help me
servlet
of the Servlet API. It contains the classes necessary for a standard, protocol-independent servlet. Every servlet must implement the Servlet interface in one
Calling a jsp page from Servlet
Calling a jsp page from Servlet  How can I do this? Suppose I have jsp page aaa.jsp. From aaa.jsp on form action I have made a call to a servlet xxx.java. In xxx.java I have written code to retrieve data from database through
servlet
"); PreparedStatement p1=con.prepareStatement("select * from Logintab where Userid...); } } } this is the code for .java servlet am able to run... .instead it redirect to pms.html   Hello Friend, The sendRedirect()method
Servlet
Servlet  I want to know the steps to write a simple servlet program... .   Hello Friend, Follow these steps: Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet. import java.io.*; import
Java Servlet : SendRedirect
Java Servlet : SendRedirect In this tutorial, you will learn how to redirect Requests to Other Resources using SendRedirect in java servlet. SendRedirect() : Response provide method sendRedirect() which sends a redirect response
Servlet
Servlet   Why is Servlet so popular?   Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web
servlet
servlet  i want to use servlet application on my web page then what should i do. I have already webspace.   Hi Friend, Please visit the following link: Servlet Tutorials Thanks
Servlet
Servlet  Can a user defined function be included in a servlet? I need information regarding servlet syntax and not JSP.   Yes, you can create user defined function in Servlets. Have a look at the following link: http
servlet
servlet  I want the full coding for uploading a file in local drive D usin jsp,java class and servlet... help me thanks in advance....   ... and servlet please and thanks in advance
Servlet
Servlet  Hi, Can any one please expalin me below topics SERVLET ENGINE 2.WHY SUPER.INIT(); Thanks alot in advance!! Regards: Akash
How to pass an arraylist from servlet to jsp?
How to pass an arraylist from servlet to jsp?  Hello, Can anyone please tell me how to pass an arraylist from servlet to jsp? I have two arraylist one of type String and the other int. How to send both the arraylists from
Advertisements
 

 

 

DMCA.com