java – Can’t redirect page using forward method in servlet

I’m trying to implement a login page using Vue.js.
When username and password are correct, the associated Servlet should redirect the user towards “/home.html”.
For doing this, I’m using the forward method of a RequestDispatcher.
This doesn’t seem to work because, instead of changing the page, it only prints the page into the response.

My index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Sing up or Sign in!</title>
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
    <link href="stylesheets/index.css" rel="stylesheet" type="text/css">
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" id="bootstrap-css" rel="stylesheet">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<div class="main">
    <div class="col-md-6 col-sm-12">
        <div class="login-form" id="login">
            <form onsubmit="return false">
                <div class="form-group">
                    <label>Username</label>
                    <input class="form-control" id="username" name="username" placeholder="username" type="text">
                    <div class="error-message">{{username}}</div>
                </div>
                <div class="form-group">
                    <label>Password</label>
                    <input class="form-control" id="password" name="password" placeholder="password" type="password">
                    <div class="error-message">{{password}}</div>
                </div>
                <button class="btn btn-black" type="submit" v-on:click="checkLogin">Login</button>
                <button class="btn btn-secondary" type="submit" v-on:click="register">Register</button>
                <br>
                <div class="error-message">{{message}}</div>
                <br>
            </form>
        </div>
    </div>
</div>
<script>


    var login = new Vue({
        el: '#login',
        data: {
            username: " ",
            password: " ",
            azione: " ",
            message: " ",
            role: 'user',
            link: '/WebTechnologies/ControllerServlet'
        },
        methods: {
            checkPattern: function () {
                let username = $('#username').val();
                let password = $('#password').val();

                if (username.match("^(a-zA-Z0-9)*$")) {
                    this.username = " ";
                } else {
                    this.username = "incorrect username";
                }

                if (!password.length > 0) {
                    this.password = "insert password";
                } else {
                    this.password = " ";
                }
                if (this.password === " " && this.username === " ") {
                    return true;
                } else {
                    return false;
                }
            },
            checkLogin: function () {
                if (this.checkPattern()) {
                    this.azione = "login";
                    console.log("Loggin in..");
                    this.requestGet();
                }
            },
            register: function () {
                if (this.checkPattern()) {
                    this.azione = "registration";
                    console.log("registration");
                    this.requestGet();
                }
            },
            requestGet: function () {
                var self = this;
                if ($('#role').prop("checked") == true) this.role = 'admin';
                $.get(this.link, {
                    azione: this.azione,
                    username: $('#username').val(),
                    password: $('#password').val(),
                    role: self.role
                }, function (data) {
                    self.message = data;

                });
            }
        }
    })
</script>
</body>
</html>

My Servlet:


package Servlets;

import Model.DAO.DAO;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "ControllerServlet", urlPatterns = {"/ControllerServlet"})
public class ControllerServlet extends HttpServlet {

    private DAO dao;
    private String url;
    private String password;
    private String username;

    @Override
    public void init(ServletConfig conf) throws ServletException {
        super.init(conf);
        ServletContext ctx = conf.getServletContext();
        this.url = ctx.getInitParameter("url");
        this.username = ctx.getInitParameter("username");
        this.password = ctx.getInitParameter("password");

        this.dao = new DAO(url, username, password);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = null;
        req.setCharacterEncoding("UTF-8");
        try {
            out = resp.getWriter();
            String azione = req.getParameter("azione");
            if (azione.equals("login")) {
                //This works, only calls another servlet that checks if user is registered already
                RequestDispatcher rd = getServletContext().getNamedDispatcher("LoginServlet");
                rd.include(req, resp);
            } else if (azione.equals("registration")) {
//This works, only calls another servlet that checks if user is registered already and if not, does the registration
                RequestDispatcher rd = getServletContext().getNamedDispatcher("RegistrationServlet");
                rd.include(req, resp);
            }else if(azione.equals("logout")){
               System.out.println("LOGOUT");
            }

            String result = (String) req.getAttribute("STATE");
            if(result.equals("SUCCESS")){
                String path = "/home.html";
//This doesn't work
                RequestDispatcher rd = getServletContext().getRequestDispatcher(path);
                rd.forward(req,resp);
            }
            out.println(result);


        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(out != null) {
                out.flush();
                out.close();
            }
        }
    }
}

home.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ripetizioni - supera il tuo esame</title>
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" id="bootstrap-css" rel="stylesheet">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <link href="stylesheets/home.css" rel="stylesheet" type="text/css">

</head>
<body class="vsc-initialized">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
    <h5 class="my-0 mr-md-auto font-weight-normal">Ripetizioni - homepage</h5>
    <nav class="my-2 my-md-0 mr-md-3">
        <a class="p-2 text-dark" href="home.html">Home</a>
        <a class="p-2 text-dark" href="repetitions.html">Le tue Ripetizioni</a>
        <a class="p-2 text-dark" href="profile.html">Il tuo profilo</a>
        <button class="p-2 text-dark" v-on:onclick="logout">Esci</button>
    </nav>
</div>

<div class="container">
    <div class="card-deck mb-3 text-center">

    </div>

    <footer class="pt-4 my-md-5 pt-md-5 border-top" id="footer">
        <div class="row">
            <div class="col-12 align-content-center">
                <div id="hour">Data attuale: {{hour}}</div>
            </div>
        </div>
    </footer>
</div>
<script>
    var footer = new Vue({
        el: '#footer',
        link: '/WebTechnologies/ControllerServlet',
        data : {
            hour: new Date().toLocaleString()
        },
        methods: {
            compare: function(a,b){
                return a == b;
            },
            logout: function () {
                let self = this;
                $.get(this.link, {azione:'logout'}, function (data) {
                    if(self.compare(data, "SUCCESS")) console.log("logout");
                    else if(self.compare(data, "ERROR")) console.log("Error");
                    else console.log("something went wrong");
                });
            }
        }
    })
</script>
</body>
</html>

Unwanted result:
enter image description here

.htaccess – Redirect 410 con parametros GET

Estoy intentando hacer un redirect 410 sobre una URL friendly que contiene parámetros GET en .htaccess

https://URL/blog/page/3/?s=busqueda

He probado con:

RewriteCond %{THE_REQUEST} /blog/page/((0-9)+)/?s=((a-z_+-)+)s (NC)
RewriteRule (.*) / (G)
RewriteCond %{QUERY_STRING} s=((a-z_+-)+) (NC)
RewriteRule (.*) / (G)

Pero no me lo reconoce, solo me reconoce esta condici├│n

RewriteCond %{QUERY_STRING} s=((a-z_+-)+) (NC)
RewriteRule (.*) / (G)

Cuando la URL es https://URL/blog/?s=busqueda

El archivo .htaccess esta dentro de la carpeta “blog”

nginx – Allow only api routes (api/*) to access port 80 and 403, redirect the rest to 443

I currently have my nginx configured for redirecting port 80 to port 443.

server {
   listen (::):443 ssl
   listen 443 ssl;

   root /var/www/my_app/public;

   server_name example.com www.example.com;

   # rest of my main config
}

# Here is port 80 listen
server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 default_server;
    listen (::):80 default_server;
}

If I comment out the second server chunk and add listen 80 default_server; listen (::):80 default_server; to above chunk, it allows both http and https access.

What I want to achieve is, if url contains example.com/api/* don’t redirect http to https, but for the rest of the urls, redirect to https.

  • example.com/api/login = allow http
  • example.com/api/test = allow http
  • example.com/api-docs = redirect to https
  • example.com/anything = redirect to https

How can I achieve this with nginx? Do I need to have 2 server blocks and move shared logic in a separate file and consider them individually for each port?

ALL websites in my WHM redirect to same domain if i hit non ssl version of url

I have a WHM cpanel with over 10 + domain
say site 1 to site 10

i install ssl in site no. 8 , 9 , 10
now if i i call non ssl version like http://www…
for site no 8,9,10 , it call the first site hosted on my whm no matter the domain called

I have most of the websites that are related to
Matrimonial script
so all sites look almost same
following is the .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

comment form code redirect to wp_comments_post.php with blank page

comment form in single post worked well. then after adding some customization, after posting a comment, it redirects to this link wp_comments_post.php with blank page.

Here is my code in comments.php so what is wrong here to make it work again?

<?php
$form_args = array(
    'fields' => array(
        'author' => ' <form class="getin_form" id="post-a-comment"> <div class="row"> <div class="col-md-6 col-sm-6">  <div class="form-group bottom35"> <input class="form-control" type="text" placeholder="First Name:" required  style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; padding: 12px 0;box-shadow: none;height: 44px;color: #a5a5a5;font-size: 14px;position: relative; "> </div> </div>',
        'email' => ' <div class="col-md-6 col-sm-6">  <div class="form-group bottom35"> <input class="form-control" type="text" placeholder="Email:" required id="email" name="email" style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; padding: 12px 0;box-shadow: none;height: 44px;color: #a5a5a5;font-size: 14px;position: relative; "> </div> </div> ',

    ),
        
        // change the title of the reply section
        'title_reply'=>'Add Comment',
        // remove "Text or HTML to be displayed after the set of comment fields"
        'comment_notes_after' => '',
        // redefine your own textarea (the comment body)
        'comment_field' => '  <div class="col-md-12 col-sm-12"> <div class="form-group bottom35"> <p class="comment-form-comment"><div class="form-group"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><br />  <textarea class="form-control" placeholder="Message"  style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; box-shadow: none; " aria-required="true"></textarea></p> </div></div> ',
        'submit_field' =>' <div class="col-sm-12" style="padding-right: 0; padding-left: 0;"> <button type="submit" class="button btnprimary form-control"> submit request </button> </div> </div> </form> </div> </div> </div> </div>',

);

comment_form($form_args);