Reputation: 763
The code for my index.jsp page is
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Welcome to the jsp page</h1>
<form action="Myservlet" method="get" >
<input type="button" value="send"/>
</form>
</body>
</html>
This is my servlet page.
package mypackge.pkg;
import java.io.IOException;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Myservlet
*/
public class Myservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Myservlet() {
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();
out.println("I am into servlet");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
This is my web.xml page
<?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" 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>WebDynamic</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>test servlet</description>
<display-name>Myservlet</display-name>
<servlet-name>Myservlet</servlet-name>
<servlet-class>mypackge.pkg.Myservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Myservlet</servlet-name>
<url-pattern>/Myservlet</url-pattern>
</servlet-mapping>
</web-app>
MY home page is the .jsp page and on hitting the send button i need to go to the servlet and display a simple text.But it does not redirect to the display the text in servlet when I hit the send button. I am using tomcat 7 and eclipse Kepler. Can anyone please help me out. Thank you.
Upvotes: 1
Views: 1368
Reputation: 304
you have not mentioned the content type in doget method of servlet that why you are not getting " i am into servlet "
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
response.setContentType("text/html; charset=UTF-8");
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
out.println("I am into servlet");
}
Upvotes: 0
Reputation: 240966
change
<input type="button" value="send"/>
to
<input type="submit" value="send"/>
Upvotes: 1