This is my code.... login page--
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[]> <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import="java.sql.*" %> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en"> <head> <!-- Created by Artisteer v3.0.0.39952 Base template (without user's data) checked by http://validator.w3.org : "This page is valid XHTML 1.0 Transitional" --> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Login Page</title> <meta name="description" content="Description" /> <meta name="keywords" content="Keywords" /> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]--> <!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]--> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="script.js"></script> <script type="text" src="NewServlet"></script> </head> <body width="100%" height="100%"> <div id="art-page-background-glare"> <div id="art-page-background-glare-image"> </div> </div> <div id="art-main"> <div class="art-nav"> <div class="art-nav-l"></div> <div class="art-nav-r"></div> <div class="art-nav-outer"> <div class="art-nav-wrapper"> <div class="art-nav-inner"> </div> </div> </div> </div> <div class="cleared reset-box"></div> <div class="art-header"> <div class="art-header-clip"> <div class="art-header-center"> <div class="art-header-png"></div> <div class="art-header-jpeg"></div> </div> </div> <div class="art-header-wrapper"> <div class="art-header-inner"> <div class="art-headerobject"></div> <div class="art-logo"> <h1 class="art-logo-name"><font size="10" face="Palatino Linotype">C.A.G. </font></h1> <h2 class="art-logo-text"><font size="8" face="Palatino Linotype">Problem Solution Book</font></h2> </div> </div> </div> </div> <div class="cleared reset-box"></div> <div class="art-sheet"> <div class="art-sheet-tl"></div> <div class="art-sheet-tr"></div> <div class="art-sheet-bl"></div> <div class="art-sheet-br"></div> <div class="art-sheet-tc"></div> <div class="art-sheet-bc"></div> <div class="art-sheet-cl"></div> <div class="art-sheet-cr"></div> <div class="art-sheet-cc"></div> <div class="art-sheet-body"> <div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell art-content"> <div class="art-post"> <div class="art-post-tl"></div> <div class="art-post-tr"></div> <div class="art-post-bl"></div> <div class="art-post-br"></div> <div class="art-post-tc"></div> <div class="art-post-bc"></div> <div class="art-post-cl"></div> <div class="art-post-cr"></div> <div class="art-post-cc"></div> <div class="art-post-body"> <div class="art-post-inner art-article"> <div class="cleared"></div> <div class="art-postcontent"> <div id="login-box"> <h2 class="art-postheader"> <img src="./images/postheadericon.png" width="22" height="21" alt="" />LOGIN </h2> <div id="login-box-name" style="margin-top:10px;">Email:</div><div id="user" style="margin-top:10px;"><input type="text" name="user" value="" size="30" maxlength="2048" /></div> <div id="login-box-name" style="margin-top:10px;">Password:</div><div id="pass" style="margin-top:10px;"><input type="password" name="pass" value="" size="30" maxlength="2048" /></div> <br /> <a href="NewServlet"><img src="images/images.jpg" width="103" height="42" style="margin-left:90px;" /></a> </div> </div> </div> <div class="cleared"></div> </div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> <div class="art-layout-cell art-sidebar1"> <div class="art-block"> <div class="art-block-body"> <div class="art-blockcontent"> <div class="art-blockcontent-body"> <p></p> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> </div> </div> <div class="cleared"></div> <div class="art-footer"> <div class="art-footer-t"></div> <div class="art-footer-l"></div> <div class="art-footer-b"></div> <div class="art-footer-r"></div> <div class="art-footer-body"> <a href="#" class="art-rss-tag-icon" title="RSS"></a> <div class="art-footer-text"> <p>Copyright �© 2012. All Rights Reserved.</p> </div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> </div> </div> <div class="cleared"> <p class="art-page-footer">Design & Developed by www.cmcltd.com</p></div> </body> </html>
java servlet file--
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author 3688895 */ public class NewServlet extends HttpServlet { /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String us= request.getParameter("user"); String ps= request.getParameter("pass"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet NewServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet NewServlet at " + request.getContextPath () + "</h1>"); out.println(us); out.println(ps); out.println("</body>"); out.println("</html>"); } finally { out.close(); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. * @return a String containing servlet description */ public String getServletInfo() { return "Short description"; }// </editor-fold> }
Output--
Servlet NewServlet at /WebApplication2
null null
Why is it not getting the parameter??? How do i accept the value in the servlet file???
Please visit the following link:
http://www.roseindia.net/servlets/PrintingNameUsingHtmlForm.shtml