0

i have to log the parameter and button's name in my log file, i have code like this jsp:

<form action="LoginCheck.jsp" name="logServlet" method="post"> 
            <br/>Username:<input type="text" name="username"/> 
            <br/>Password:<input type="password" name="password"/> 
            <br/><input type="submit" value="Submit" name="bt"/> 
        </form>

servlet(doGET):

String USERNAME, PASSWORD;            
            USERNAME = request.getParameter("username");
            PASSWORD = request.getParameter("password");
            String bt = request.getParameter("bt");
            System.out.println("button value = " + bt);
            writer.println("Username    :" + USERNAME + "<br>" + "Password  :" + PASSWORD + "<br>" + bt);

my result: Username : null Password : null null

just wonder how to get the parameter? thanks...

raymond_wmt
  • 31
  • 2
  • 2
  • 8

2 Answers2

0

In the JSP you have given the method as POST and in servlet you have called the doGet() method.

So in your servlet use the doPost() instead of doGet() and you will get your values.

Santino 'Sonny' Corleone
  • 1,735
  • 5
  • 25
  • 52
0

I wonder how could you get your values printed from your servlet page as you have specified the form action as the name of your JSP page instead of your servlet page..

So first the change the form action as the name of your servlet page which is I think logServlet in your case instead of specifying the name of JSP page i.e LoginCheck.jsp and then make the changes as specified by Santino i.e. use doPost() in your Servlet instead of doGet()

Java Enthusiast
  • 654
  • 7
  • 19
  • just a simple question again. can i have 2 actions in one
    ?? because i create the loginCheck.jsp is for some if...else statement. and the logServlet is to record the parameters filled by user. TQ
    – raymond_wmt Jun 28 '14 at 15:39
  • No you cannot have 2 actions in one form..if you have different buttons in one form then either you can give the form action of same page and then check for button click and send to different pages correspondingly or you can send it to servlet page and then check button click over there..but 2 actions in one form not possible – Java Enthusiast Jun 28 '14 at 16:52
  • In your case what you can do that is send it to single servlet page and do both the actions on that page i.e. logincheck and record parameters – Java Enthusiast Jun 28 '14 at 16:53
  • @user3736728 If it helped do tick the answer – Java Enthusiast Jun 30 '14 at 05:51