<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shahin Idrisi</title>
    <description>The latest articles on DEV Community by Shahin Idrisi (@shahinn0x).</description>
    <link>https://dev.to/shahinn0x</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3072579%2F90285acc-5d72-43a9-9ac2-bd463ed5d2db.png</url>
      <title>DEV Community: Shahin Idrisi</title>
      <link>https://dev.to/shahinn0x</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shahinn0x"/>
    <language>en</language>
    <item>
      <title>🔁 Understanding Model, Controller, and Route in MERN Stack with Example</title>
      <dc:creator>Shahin Idrisi</dc:creator>
      <pubDate>Mon, 28 Jul 2025 16:54:23 +0000</pubDate>
      <link>https://dev.to/shahinn0x/understanding-model-controller-and-route-in-mern-stack-with-example-e4i</link>
      <guid>https://dev.to/shahinn0x/understanding-model-controller-and-route-in-mern-stack-with-example-e4i</guid>
      <description>&lt;p&gt;When building a full-stack application using the MERN stack (MongoDB, Express, React, Node.js), the backend architecture plays a critical role in ensuring the application is well-structured, scalable, and easy to maintain.&lt;/p&gt;

&lt;p&gt;In this blog post, we’ll explore the relationship between Model, Controller, and Route in a MERN backend setup and walk through a dummy example to help you understand how they communicate with one another.&lt;/p&gt;

&lt;p&gt;📦 &lt;strong&gt;What is the MVC Pattern?&lt;/strong&gt;&lt;br&gt;
The MERN backend usually follows the MVC pattern:&lt;/p&gt;

&lt;p&gt;Model – Interacts with the database (MongoDB)&lt;/p&gt;

&lt;p&gt;Controller – Contains logic to handle requests/responses&lt;/p&gt;

&lt;p&gt;Route – Defines the API endpoints&lt;/p&gt;

&lt;p&gt;View – In MERN, this is handled by React on the frontend&lt;/p&gt;

&lt;p&gt;🧠** Flow of Communication**&lt;br&gt;
Here's how everything connects:&lt;/p&gt;

&lt;p&gt;Client sends a request to an API endpoint (like /api/students/add)&lt;/p&gt;

&lt;p&gt;Route catches the request and passes it to the correct Controller&lt;/p&gt;

&lt;p&gt;Controller uses a Model to interact with MongoDB&lt;/p&gt;

&lt;p&gt;Model returns data to Controller, which sends a response back to Client&lt;/p&gt;

&lt;p&gt;📘 &lt;strong&gt;Dummy Example: Student Management API&lt;/strong&gt;&lt;br&gt;
Let’s create a basic API to manage student records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Folder Structure:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
backend/&lt;br&gt;
├── controllers/&lt;br&gt;
│   └── studentController.js&lt;br&gt;
├── models/&lt;br&gt;
│   └── studentModel.js&lt;br&gt;
├── routes/&lt;br&gt;
│   └── studentRoutes.js&lt;br&gt;
├── server.js&lt;/p&gt;

&lt;p&gt;1️⃣ Model – models/studentModel.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require('mongoose');

const studentSchema = new mongoose.Schema({
  name: { type: String, required: true },
  rollNumber: { type: Number, required: true },
  class: { type: String, required: true },
});

const Student = mongoose.model('Student', studentSchema);

module.exports = Student;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;What it does: Defines a Mongoose schema to store student info in MongoDB.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;2️⃣ Controller – controllers/studentController.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Student = require('../models/studentModel');

// Get all students
const getAllStudents = async (req, res) =&amp;gt; {
  try {
    const students = await Student.find();
    res.status(200).json(students);
  } catch (error) {
    res.status(500).json({ message: 'Error fetching students' });
  }
};

// Add a new student
const addStudent = async (req, res) =&amp;gt; {
  const { name, rollNumber, class: studentClass } = req.body;

  try {
    const newStudent = new Student({ name, rollNumber, class: studentClass });
    await newStudent.save();
    res.status(201).json(newStudent);
  } catch (error) {
    res.status(400).json({ message: 'Failed to add student' });
  }
};

module.exports = {
  getAllStudents,
  addStudent
};


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;What it does: Contains the logic to get students from DB or add a new one.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;3️⃣ Routes – routes/studentRoutes.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const express = require('express');
const router = express.Router();
const { getAllStudents, addStudent } = require('../controllers/studentController');

router.get('/', getAllStudents);         // GET /api/students/
router.post('/add', addStudent);         // POST /api/students/add

module.exports = router;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;What it does: Maps API endpoints to controller functions.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;4️⃣ Server Entry – server.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const express = require('express');
const mongoose = require('mongoose');
const studentRoutes = require('./routes/studentRoutes');
const app = express();

// Middleware
app.use(express.json());

// Routes
app.use('/api/students', studentRoutes);

// Connect MongoDB and start server
mongoose.connect('mongodb://127.0.0.1:27017/school')
  .then(() =&amp;gt; {
    console.log('MongoDB Connected');
    app.listen(5000, () =&amp;gt; console.log('Server running on port 5000'));
  })
  .catch((err) =&amp;gt; console.log(err));


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;_What it does: Connects all parts and starts the Express server.&lt;br&gt;
_&lt;/p&gt;

&lt;p&gt;🔄 &lt;strong&gt;How a Request Flows&lt;/strong&gt;&lt;br&gt;
When a POST request is sent to /api/students/add:&lt;/p&gt;

&lt;p&gt;Route in studentRoutes.js catches it&lt;/p&gt;

&lt;p&gt;It calls addStudent() from studentController.js&lt;/p&gt;

&lt;p&gt;The controller creates a new Student using the Model&lt;/p&gt;

&lt;p&gt;The Model saves it to MongoDB&lt;/p&gt;

&lt;p&gt;A JSON response is sent back to the client&lt;/p&gt;

&lt;p&gt;🧩 &lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
Understanding the communication between Model, Controller, and Route is key to mastering backend development in MERN. Once you get this flow, your projects become much easier to scale and maintain.&lt;/p&gt;

&lt;p&gt;🔧 Want to connect this backend to a React frontend? Let me know in the comments and I’ll write a follow-up!&lt;/p&gt;

&lt;p&gt;✍️ &lt;strong&gt;Author: Shahin Idrisi&lt;/strong&gt;&lt;br&gt;
💬 Feel free to reach out for help with your MERN projects!&lt;/p&gt;

</description>
      <category>fullstack</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JAVA Servlet Tutorial for Beginners with HTML example</title>
      <dc:creator>Shahin Idrisi</dc:creator>
      <pubDate>Tue, 22 Apr 2025 13:52:16 +0000</pubDate>
      <link>https://dev.to/shahinn0x/java-servlet-tutorial-for-beginners-with-html-example-5dng</link>
      <guid>https://dev.to/shahinn0x/java-servlet-tutorial-for-beginners-with-html-example-5dng</guid>
      <description>&lt;p&gt;Learn how to create a Java Servlet and connect it with an HTML form. Step-by-step guide for beginners with code examples.&lt;/p&gt;

&lt;p&gt;🚀&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
If you're diving into Java web development, servlets are one of the first things you’ll encounter. In this blog, we’ll walk through a simple example of how to create a servlet and connect it with an HTML form.&lt;/p&gt;

&lt;p&gt;By the end, you’ll understand how to send data from an HTML page to a servlet and process it on the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 What is a Java Servlet?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Java Servlet is a Java class used to handle HTTP requests and responses. It runs on a Java EE-compliant server such as Apache Tomcat, GlassFish, WildFly, or Jetty. Servlets act as a bridge between your front-end (HTML) and back-end (Java logic), forming the foundation of Java-based web applications.&lt;br&gt;
If you're just building simple web apps or learning servlets, Tomcat is perfect.&lt;br&gt;
But if you're building enterprise applications, you might prefer GlassFish or WildFly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔄 How a Servlet Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When a user fills out a form on your website and clicks Submit, this is what happens behind the scenes in a Java Servlet:&lt;br&gt;
User submits a form (like typing their name).&lt;br&gt;
The browser sends this form data as an HTTP request to the server (e.g., Tomcat).&lt;br&gt;
The server (like Tomcat) receives the request and looks for the correct servlet to handle it. This is done by matching the URL in the request to the servlet’s configuration (in web.xml or @WebServlet).&lt;br&gt;
Servlet container (Tomcat) creates two things:&lt;br&gt;
HttpServletRequest: This object holds the data the user sent (like the name they typed in the form).&lt;br&gt;
HttpServletResponse: This is used by the servlet to send the response (what the user will see after submitting the form).&lt;br&gt;
The servlet is then called to process the request:&lt;br&gt;
If the request is a GET (a simple page load), it calls doGet().&lt;br&gt;
If it’s a POST (like submitting a form), it calls doPost().&lt;br&gt;
Inside the doPost() (or doGet()), the servlet:&lt;br&gt;
Reads the form data using request.getParameter().&lt;br&gt;
Processes it (e.g., checks if the name is valid or stores it in a database).&lt;br&gt;
Prepares a response, like a message, using response.getWriter().&lt;br&gt;
The servlet sends back the response to the browser. The user sees the result (like "Hello, John!").&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0fizilip5mzhqveh51qx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0fizilip5mzhqveh51qx.jpg" alt=" " width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🛠️ &lt;strong&gt;Tools Required&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;- NetBeans or Eclipse&lt;/li&gt;
&lt;li&gt;- Apache Tomcat (or use NetBeans with built-in Tomcat)&lt;/li&gt;
&lt;li&gt;- Java SDK&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;✍️ &lt;strong&gt;Step-by-Step Example&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the HTML Form
Create a file named index.html:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;head&amp;gt;
        &amp;lt;title&amp;gt;TODO supply a title&amp;lt;/title&amp;gt;
        &amp;lt;meta charset="UTF-8"&amp;gt;
        &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;div&amp;gt;TODO write content&amp;lt;/div&amp;gt;
        &amp;lt;h1&amp;gt;This is shortform converter&amp;lt;/h1&amp;gt;
        &amp;lt;form method="POST" action=MyServlet"&amp;gt;
              Name: &amp;lt;input type="text" name="username"&amp;gt;&amp;lt;br&amp;gt;
              &amp;lt;input type="submit" value="Submit"&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidxjsrez5b2k0y45k0tt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidxjsrez5b2k0y45k0tt.png" alt=" " width="800" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the Java Servlet
Create a new Servlet named MyServlet.java:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author SERAJ
 */
public class MyServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP &amp;lt;code&amp;gt;GET&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("&amp;lt;!DOCTYPE html&amp;gt;");
            out.println("&amp;lt;html&amp;gt;");
            out.println("&amp;lt;head&amp;gt;");
            out.println("&amp;lt;title&amp;gt;Servlet Servlet1&amp;lt;/title&amp;gt;");            
            out.println("&amp;lt;/head&amp;gt;");
            out.println("&amp;lt;body&amp;gt;");
            String name = request.getParameter("username");
            out.println("&amp;lt;h2&amp;gt;Hello, " + name + "!&amp;lt;/h2&amp;gt;");
            out.println("&amp;lt;/body&amp;gt;");
            out.println("&amp;lt;/html&amp;gt;");
        }
    }

    // &amp;lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."&amp;gt;
    /**
     * Handles the HTTP &amp;lt;code&amp;gt;GET&amp;lt;/code&amp;gt; method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt; method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// &amp;lt;/editor-fold&amp;gt;

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2xifqtnd1er11y7wk0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2xifqtnd1er11y7wk0l.png" alt=" " width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Configure web.xml
Inside your project’s WEB-INF/web.xml file, add this:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;servlet-name&amp;gt;MyServlet&amp;lt;/servlet-name&amp;gt;
  &amp;lt;servlet-class&amp;gt;MyServlet&amp;lt;/servlet-class&amp;gt;
&amp;lt;/servlet&amp;gt;

&amp;lt;servlet-mapping&amp;gt;
  &amp;lt;servlet-name&amp;gt;MyServlet&amp;lt;/servlet-name&amp;gt;
  &amp;lt;url-pattern&amp;gt;/MyServlet&amp;lt;/url-pattern&amp;gt;
&amp;lt;/servlet-mapping&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgw44r6hyhn6g0sz1a6pj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgw44r6hyhn6g0sz1a6pj.png" alt=" " width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run Your Project
Deploy the project on Tomcat.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Open index.html in your browser.&lt;/p&gt;

&lt;p&gt;Enter a name and click Submit.&lt;/p&gt;

&lt;p&gt;You should see:&lt;br&gt;
👉 "Hello, [Your Name]!"&lt;/p&gt;

&lt;p&gt;🔧 &lt;strong&gt;Common Errors &amp;amp; Fixes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbp3yh2iw3ys8i8imf02r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbp3yh2iw3ys8i8imf02r.png" alt=" " width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
You’ve now built your first Java Servlet that connects to an HTML form! This is the foundation for building more advanced web apps using Java.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
