index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>sendRedirect() Method Example</title>
</head>
<body>
<form action="SearchServlet" method="get">
<input type="text" name="name">
<input type="submit" value="Google Search">
</form>
</body>
</html>
SearchServlet.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SearchServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name=request.getParameter("name");
response.sendRedirect("https://www.google.co.in/#query="+name);
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>sendRedirect() Method Example</title>
</head>
<body>
<form action="SearchServlet" method="get">
<input type="text" name="name">
<input type="submit" value="Google Search">
</form>
</body>
</html>
SearchServlet.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SearchServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name=request.getParameter("name");
response.sendRedirect("https://www.google.co.in/#query="+name);
}
}
web.xml
<servlet>
<description></description>
<display-name>SearchServlet</display-name>
<servlet-name>SearchServlet</servlet-name>
<servlet-class>SearchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SearchServlet</servlet-name>
<url-pattern>/SearchServlet</url-pattern>
</servlet-mapping>
</web-app>
0 comments:
Post a Comment