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 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
}
}
View Answers
Related Tutorials/Questions & Answers:
Redirect from servlet to servletRedirect 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 servletredirect 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 neededservlet 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 neededservlet 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
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
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
send redirect in JSP - JSP-Servletsend
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
ArrayList from JSP to Servlet - JSP-ServletArrayList
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
servletservlet how to interact with a
servlet from a swing program
Call servlet from javascript - JSP-ServletCall
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 ServletServlet how to navigate one
servlet page to another
servlet page
write to file from servlet - JSP-Servletwrite 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
Getting data from servlet into javascriptGetting 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
servletservlet can i stoar record in variable which selected
from table in
servlet servletservlet is there any way to include pdf's in
servlet servletservlet How many times the
servlet is accessed
servletservlet what are the methods and interfaces in the
servlet api ?
Servlet Tutorials
servletservlet how to read a file
from different folder using filereader in
servlet
Hello Friend,
Please visit the following link:ADS_TO_REPLACE_1
http://www.roseindia.net/servlets/
servlet-read-file.shtml
Here you
Send Redirect in Servlet Send
Redirect in
Servlet
... or not. If the password entered by the
user is correct then the
servlet will
redirect... of our
servlet, then there we should use sendRedirect()
method.
In send
servletservlet what are the all necessary configuration to run a
servlet servletservlet I designed 1 html form & a
servlet but when I click on form I don't get output of
servlet Please help
servletservlet i want to create a login page with
servlet using database mysql? only in
servlet not in jsp plzz help me out
servletservlet I designed 1 html form & a
servlet but when I click on form I don't get output of
servlet Please help
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
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.
ServletServlet What must be implemented by all Servlets?
The
Servlet Interface must be implemented by all servlets
servletservlet i want a program for counting the no of times the
servlet has been invoked
servletservlet how to create a login form using
servlet using submit,edit delete button
servletservlet 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
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 session - JSP-Servletservlet 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
ServletServlet 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
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
servletservlet 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:ADS_TO_REPLACE_1
Servlet Tutorials
Thanks
ServletServlet 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
servletservlet 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
ServletServlet Hi,
Can any one please expalin me below topics
SERVLET ENGINE
2.WHY SUPER.INIT();
Thanks alot in advance!!
Regards:
Akash
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 Dear Deepak,
is it compulsary to write the sevice()
becoz i ve seen some example which does not ve sevice()..is it tue? plz replay me
with thanks
praveen
servletservlet plz can anyone give me the link of javax library jar file. i badly need that. thanks in advance
Please visit the following link:
Download
Servlet API
servletservlet I want a fully readymade project on online voting system with code in java
servlet and database backend as msaccess.can u plz send me as soon as possible
Calling a jsp page from ServletCalling 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 the same error
<web-app>
<servlet>
<
servlet-name>InsertServlet</
servlet-name>
<
servlet-class>InsertServlet</
servlet-class>
</servlet>
<
servlet-mapping>
<
servlet-name>