Assignment 8
Assignment 8
Design a login page with entries for name, mobile number email id and login
button. Use struts and perform following validations
a. Validation for correct names
b. Validation for mobile numbers
c. Validation for email id
d. Validation if no entered any value
e. Re-display for wrongly entered values with message
f. Congratulations and welcome page upon successful entries
StrutsLoginApp/
│── src/
│ ├── com.example.action/
│ │ ├── LoginAction.java
│ ├── struts.xml
│── WebContent/
│ ├── index.jsp (Login Page)
│ ├── welcome.jsp (Welcome Page)
│ ├── error.jsp (Error Page)
│ ├── WEB-INF/
│ │ ├── web.xml
│ │ ├── struts-config.xml
<struts>
<package name="default" extends="struts-default">
import com.opensymphony.xwork2.ActionSupport;
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h2>Congratulations! You have successfully logged in.</h2>
</body>
</html>
<html>
<head>
<title>Error</title>
</head>
<body>
<h2 style="color:red;">Oops! Something went wrong.</h2>
<p>Please go back and check your entries.</p>
</body>
</html>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Steps to Run
1. Install Apache Tomcat and configure your IDE (Eclipse/IntelliJ).
2. Place Struts 2 JAR files in the WEB-INF/lib directory.
3. Deploy the project in Tomcat's webapps folder.
4. Start the server and open in a browser:
http://localhost:8080/StrutsLoginApp/index.jsp
5. Enter:
o ✅ Name: John Doe ✅
o ✅ Mobile: 9876543210 ✅
o ✅ Email: [email protected] ✅
o Click Login → Redirects to welcome.jsp
6. If wrong details are entered, errors are displayed on index.jsp.
Expected Output
Login Page (index.jsp)
+---------------------+
| Name: [__________] | (Error: Name must contain only alphabets)
| Mobile: [________] | (Error: Invalid mobile number)
| Email: [_________] | (Error: Invalid email format)
+---------------------+
[ Login ]