• Post Reply Bookmark Topic Watch Topic
  • New Topic

Action page is not loaded in servlet  RSS feed

 
Mithun Jadav
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

import java.io.*;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;





/**
* Servlet implementation class A
*/
@WebServlet("/A")
public class A extends HttpServlet {


/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
public void init()throws ServletException{
System.out.println(getServletConfig());
String s=getInitParameter("Name");
String s1=getInitParameter("Password");
System.out.println("Name"+s);
System.out.println("Password"+s1);
ServletConfig config=getServletConfig();
System.out.println(config);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

ServletConfig config=getServletConfig();
String s=config.getInitParameter("Name");
String s1=config.getInitParameter("Password");
response.setContentType("text/html");
PrintWriter out=response.getWriter();

out.println("Your Name is:"+s);
out.println("Your Password is:"+s1);



}

}
there ia also a HTML page containg a submit button,when i run this program in eclipse mars....the html page is displayed,but when i click submit button it does not redirect to servlet page.after reruning the project error-get method is not supported.

htmlpage.
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><center>
<form action="A" method="post">
<input type="button" value="submit">
</form>
</center>
</body>
</html>

web.xml.

<?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_3_0.xsd" version="3.0">
<display-name>Demo</display-name>

<servlet>
<servlet-name>A</servlet-name>
<servlet-class>A</servlet-class>
<init-param>
<param-name>Name</param-name>
<param-value>Mithun Sarkar</param-value>
</init-param>

<init-param>
<param-name>Password</param-name>
<param-value>1234r</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>A</servlet-name>
<url-pattern>"/A"</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Welcome.html</welcome-file>
</welcome-file-list>
</web-app>
I am using apache v-8. but using apache facing problem,default port is 8080,i chnged it to 80 after seeing that 80 is open.jdk-1.8,OS-windows 7.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


ALL classes used in the servlet environment MUST be in a package. This has come up many times before. Without a specified package, the JVM looks in the "current" directory, something you have no control over.

Bill
 
Mithun Jadav
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:

ALL classes used in the servlet environment MUST be in a package. This has come up many times before. Without a specified package, the JVM looks in the "current" directory, something you have no control over.

Bill
thans sir it works.
sir i am using eclipse mars.i am learning now.i dont want annotation.how i can disable them.when i create Deoployment descriptir by own.those annotation conflicts each other with DD.please help
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion, based on years of watching people start with servlets, you should not be using an IDE at all.

The reason being that, as you have found out, an IDE will do stuff behind your back and prevent you from grasping various important points.

My suggestion is to use a programmer's editor that is aware of Java syntax to create your code and the ANT utility to control compiling, file copying, etc. Keep a browser window open on a local copy of the JavaDocs for reference. Use a local copy of Tomcat to test with and study the example code that comes with Tomcat for best practices.

Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!