Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added MVCModel/libs/commons-logging-1.2.jar
Binary file not shown.
Binary file added MVCModel/libs/javax.servlet-api-4.0.0.jar
Binary file not shown.
Binary file added MVCModel/libs/javax.servlet.jsp.jstl-1.2.1.jar
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file added MVCModel/libs/mysql-connector.jar
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions MVCModel/src/main/com/myApp/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main.com.myApp.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter
{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}

40 changes: 40 additions & 0 deletions MVCModel/src/main/com/myApp/controller/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main.com.myApp.controller;

import main.com.myApp.model.UserModel;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HomeController
{

@RequestMapping("/")
public String showHomePage(Model model)
{
model.addAttribute("userModel" , new UserModel());
return "formPage";
}

@RequestMapping("/processForm")
public String processForm(@ModelAttribute("userModel") UserModel userModel, Model model)
{

String usernameAsUpperCase = userModel.getUserName().toUpperCase();
userModel.setUserName(usernameAsUpperCase);

//step1: add bean to model
model.addAttribute("userModelResult" , userModel);

//step2: return view page
return "resultPage";
}

@RequestMapping("/showTestForm")
public String showTestForm()
{
return "test";
}
}
24 changes: 24 additions & 0 deletions MVCModel/src/main/com/myApp/model/UserModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main.com.myApp.model;

import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;

import javax.swing.*;

@Component
@Setter
@Getter
public class UserModel
{
private String userName;
private String password;
private String country;
private String programmingLanguage;
private String operatingSystem;
}
/**
* 1- define UserModel inside the model object (/showForm)
* 2- linking between the fields inside the jsp page and attributes inside the jsp page
* 3- recieve the UserModel object inside the /process after filling it in the form page
*/
35 changes: 35 additions & 0 deletions MVCModel/src/main/webapp/WEB-INF/application-context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">


<!-- Step 3: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>

<!-- Step 4: Add support for component scanning -->
<context:component-scan base-package="main.com.myApp" />
<!-- Step 5: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>

</beans>








68 changes: 68 additions & 0 deletions MVCModel/src/main/webapp/WEB-INF/view/formPage.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Styled Form</title>

<!-- Link to custom stylesheet -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/style.css">

<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/bootstrap.min.css">

</head>
<body class="bg-light">
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<h2 class="text-center mb-4">User Form</h2>
<form:form action="processForm" modelAttribute="userModel" class="p-4 border rounded bg-white shadow-sm">

<!-- Username Input -->
<div class="form-group mb-3">
<form:input type="text" placeholder="Username" path="userName" class="form-control" />
</div>

<!-- Password Input -->
<div class="form-group mb-3">
<form:input type="password" placeholder="Password" path="password" class="form-control" />
</div>

<!-- Country Dropdown -->
<div class="form-group mb-3">
<form:select path="country" class="form-control">
<form:option value="Egypt" label="Egypt" />
<form:option value="Brazil" label="Brazil" />
<form:option value="Saudia Arabia" label="KSA" />
</form:select>
</div>

<!-- Programming Language Radio Buttons -->
<div class="form-group mb-3">
<label>Preferred Programming Language</label><br>
Java <form:radiobutton path="programmingLanguage" value="Java" />
C# <form:radiobutton path="programmingLanguage" value="C#" />
PHP <form:radiobutton path="programmingLanguage" value="PHP" />
Ruby <form:radiobutton path="programmingLanguage" value="Ruby" />
</div>

<!-- Operating System Checkboxes -->
<div class="form-group mb-3">
<label>Preferred Operating System</label><br>
Linux <form:checkbox path="operatingSystem" value="Linux" />
Mac OS <form:checkbox path="operatingSystem" value="Mac OS" />
MS Windows <form:checkbox path="operatingSystem" value="MS Windows" />
</div>

<!-- Submit Button -->
<div class="form-group">
<input type="submit" class="btn btn-danger btn-block" />
</div>
</form:form>
</div>
</div>
</div>

</body>
</html>
19 changes: 19 additions & 0 deletions MVCModel/src/main/webapp/WEB-INF/view/resultPage.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>

<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/style.css">
</head>
<body >
<h1>Hello to Student App</h1>
<h3>username is : ${userModelResult.userName} </h3>
<h3>password is : ${userModelResult.password} </h3>
<h3>password is : ${userModelResult.country} </h3>
<h3>password is : ${userModelResult.programmingLanguage} </h3>
<h3>first prog lang is : ${userModelResult.operatingSystem} </h3>
<%-- <h3>second prog lang is : ${userModelResult.operatingSystem[1]} </h3>--%>

</body>
</html>


19 changes: 19 additions & 0 deletions MVCModel/src/main/webapp/WEB-INF/view/test.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%--
Created by IntelliJ IDEA.
User: ahmedSalah
Date: 12/13/2024
Time: 10:15 AM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/style.css">

</head>
<body>
<h1>testing</h1>
</body>
</html>
26 changes: 26 additions & 0 deletions MVCModel/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">

<!-- Spring MVC Configs -->

<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>
7 changes: 7 additions & 0 deletions MVCModel/src/main/webapp/resources/css/bootstrap.min.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions MVCModel/src/main/webapp/resources/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h1
{
color: red;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 0 additions & 29 deletions Task2/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions Task2/.idea/compiler.xml

This file was deleted.

90 changes: 0 additions & 90 deletions Task2/.idea/libraries/javax_annotation_api_1_3_2.xml

This file was deleted.

Loading