Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Capture login information and pass to Java method

I hope this is a simple question.  I know Java, but I've just started learning JSP, and I'm having a difficult time understanding how I can capture the username and password from a login page to pass it to my java method.  I was able to create a variable linking to a samplemethod

Sample.SampleMethod sm = new Sample.SampleMethod();
String jason = sm.test("Input String");

but how would I do the same for the following?

<td class="formPromptTd">User Name:</td>
<td class="formReqTd">*</td>
<td class="formElementTd"><input type="text" name="USERNAME" size="20" tabindex=1 Class="formText"></td>
</tr>


Thanks in advance
0
jhughes4
Asked:
jhughes4
  • 4
1 Solution
 
TimYatesCommented:
file1.jsp
--------------------

<form action="file2.jsp">
    <table>
        <tr>
            <td class="formPromptTd">User Name:</td>
            <td class="formReqTd">*</td>
            <td class="formElementTd"><input type="text" name="USERNAME" size="20" tabindex=1 Class="formText"></td>
        </tr>
    </table>
</form>

file2.jsp
--------------------
<%
    String username = request.getParameter( "USERNAME" ) ;
    out.println( "<h1>The user entered the username" + username + "</h1>" ) ;
%>
0
 
TimYatesCommented:
SOrry, file1.jsp should be:

<form action="file2.jsp">
    <table>
        <tr>
            <td class="formPromptTd">User Name:</td>
            <td class="formReqTd">*</td>
            <td class="formElementTd"><input type="text" name="USERNAME" size="20" tabindex=1 Class="formText"></td>
        </tr>
        <tr>
            <td colspan="3">
                <input type="Submit" value="OK">
            </td>
        </tr>
    </table>
</form>
0
 
jhughes4Author Commented:
Thanks for the quick response.  

If I wanted to pass say both username and password to a java method would I do the following?
<form action="sample"> //for username
<form action="sample"> //for password

assuming that sample.class is in my classpath?

sorry, but I had one other question.  In Java if a method has input paramters of both String and int I would do the following:

Sample.SampleMethod sm = new Sample.SampleMethod();
String jason = sm.test("Input String", 10);

How would I do this with form action?  I've increased the points since I've asked additional questions.  thanks again.

0
 
TimYatesCommented:
> If I wanted to pass say both username and password to a java method would I do the following?

Nope, just put 2 input boxes inside the main form:

        <tr>
            <td class="formPromptTd">User Name:</td>
            <td class="formReqTd">*</td>
            <td class="formElementTd"><input type="text" name="USERNAME" size="20" tabindex=1 Class="formText"></td>
        </tr>
        <tr>
            <td class="formPromptTd">Password:</td>
            <td class="formReqTd">*</td>
            <td class="formElementTd"><input type="password" name="PASSWORD" size="20" tabindex=1 Class="formText"></td>
        </tr>
0
 
TimYatesCommented:
>  In Java if a method has input paramters of both String and int I would do the following:

You can just call java methods direct fomr the JSP:

<%
    Sample.SampleMethod sm = new Sample.SampleMethod();
    String jason = sm.test("Input String", 10);
%>

as request.getParameter() returns a String, you have to do a bit of tweaking ;-)

<%
    String a = request.getParameter( "inputstring" ) ;
    String b = request.getParameter( "anIntValue" ) ;
    int ib = 0 ;
    if( b != null )
        ib = Integer.parseInt( b ) ;
    Sample.SampleMethod sm = new Sample.SampleMethod();
    String jason = sm.test( a, ib );
%>
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now