Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Creating Android Application. For this assignment, you will be creating a login

ID: 666601 • Letter: C

Question

Creating Android Application.

For this assignment, you will be creating a login screen with two input fields (username and password) and one button (login button).

In Module 02, you created a basic “Hello World” application and screen. After reviewing the video, add a login screen to this application.

The user must enter a valid username and password (these can be hard-coded into the system).

Click the Login Button.

If the Username and password are correct, take them to a user screen. If NOT, reject and have them try again. This requires you to read the input inside the textboxes and respond to the button's onClick event.

Advance the application by making it handle the Spanish and French languages using the strings.xml files appropriately.

Explanation / Answer

index.html
========

<form action="login" method="post">

   <table>

   <tr>

   <td><font face="verdana" size="2px">Name:</font></td>

    <td><input type="text" name="userName"></td>

   </tr>

   <tr>

<td><font face="verdana" size="2px">Password:</font></td>

<td><input type="password" name="userPassword"></td>

   </tr>

   </table>

   <input type="submit" value="Login">

</form>

web.xml
========

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet>

<servlet-name>loginServlet</servlet-name>

<servlet-class>java4s.OnServletLogin</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>loginServlet</servlet-name>

<url-pattern>/login</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

</web-app>

OnServletLogin.java
=================

package java4s;

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;

public class OnServletLogin extends HttpServlet  

{

protected void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException

{

PrintWriter pw=res.getWriter();

res.setContentType("text/html");

String user=req.getParameter("userName");

String pass=req.getParameter("userPassword");

if(user.equals("admin")&&pass.equals("admin"))

pw.println("Welcome!");

   else

pw.println("Try Again!");

pw.close();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote