0% found this document useful (0 votes)
17 views6 pages

WT 8

The document describes the configuration files for a Struts login application including struts.xml, web.xml, LoginAction.java, success.jsp, login.jsp, and error.jsp. It defines the form beans, actions, and mappings for the login workflow as well as the Java action class and JSP pages for login, success, and error.

Uploaded by

kartiknikumbh11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

WT 8

The document describes the configuration files for a Struts login application including struts.xml, web.xml, LoginAction.java, success.jsp, login.jsp, and error.jsp. It defines the form beans, actions, and mappings for the login workflow as well as the Java action class and JSP pages for login, success, and error.

Uploaded by

kartiknikumbh11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Code:-

File Name: - struts.xml

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


<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="LoginForm" type="com.example.struts.LoginForm"/>
</form-beans>

<action-mappings>
<action path="/login" type="com.example.struts.LoginAction" name="LoginForm"
validate="true" input="/login.jsp">
<forward name="success" path="/success.jsp"/>
</action>
</action-mappings>
<message-resources parameter="com.example.struts.ApplicationResources"/>
</struts-config>

File Name: - web.xml

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


<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-
app_3_1.xsd">
<filter>
<filter-name>Login Validation</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>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
File Name: - LoginAction.java

package com.myapp.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts.action.ActionMessage;
public class LoginAction extends ActionSupport {

private String name;


private String mobileno;
private String email;

public String getMobileno() {


return mobileno;
}

public void setMobileno(String mobileno) {


this.mobileno = mobileno;
}

public String getEmail() {


return email;
}

public void setEmail(String email) {


this.email = email;
}

public String getName() {


return name;
}

public void setName(String string) {


name = string;
}

public LoginAction() {
super();
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();

if (name == null || name.trim().equals("")) {


errors.add("name", new ActionMessage("error.name.required"));
} else if (!name.matches("[a-zA-Z ]+")) {
errors.add("name", new ActionMessage("error.name.invalid"));
}

if (mobileno == null || mobileno.trim().equals("")) {


errors.add("mobile", new ActionMessage("error.mobile.required"));
} else if (!mobileno.matches("\\d{10}")) {
errors.add("mobile", new ActionMessage("error.mobile.invalid"));
}

if (email == null || email.trim().equals("")) {


errors.add("email", new ActionMessage("error.email.required"));
} else if (!email.matches("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}")) {
errors.add("email", new ActionMessage("error.email.invalid"));
}

return errors;
}
}

File Name: - success.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Success Page</title>
</head>
<body style="text-align:center; margin-top: 10%">
<h1>Login Successful</h1>
</body>
</html>

File Name: - login.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login Page</title>
</head>
<body style="margin-left: 40%; margin-top: 10%">
<h1>Login Form</h1>
<s:form action="login_action">
<s:textfield name="name" label="Enter your Name: "/>
<s:textfield name="mobileno" label="Enter your Mobile No: "/>
<s:textfield name="email" label="Enter your Email: "/>
<s:submit value="Login" align="center"/>
</s:form>
</body>
</html>
File Name: - error.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Error Page</title>
</head>
<body style="text-align:center; margin-top: 10%">
<h1>Error Page</h1>
</body>
</html>
Output:

You might also like