• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Action page is not loaded in servlet

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic