About SpringMVC Screen Transitions

Asked 2 years ago, Updated 2 years ago, 62 views

(java)
We are developing Java Web software using SpringSTS on Eclipse 4.6.
When I transition from the first login screen to the next menu, jsp will run
The corresponding controller class GET method will not be executed.
I just need to fit the image for the title
I am not sure why it does not transition to the control class.
The relevant sources are as follows:

<Login Control>

package jp.vikingeg.VESales.control;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.announcement.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.announcement.RequestMapping;
import org.springframework.web.bind.announcement.RequestMethod;
import org.springframework.web.bind.announcement.RequestParam;
import jp.vikingegg.VESales.common.EnvironmentInfo;
import jp.vikingegg.VESales.service.LoginService;

@ Controller
@RequestMapping(value="/")
public class LoginController {
    private static final logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private LoginService loginService;

    public LoginController() {

        loginService = new LoginService();
    }

    @RequestMapping(value="/", method=RequestMethod.GET)
    public String getLogin(Local locale, Model model) {

        logger.info("VikingEgg(LoginGET)The client locale is {}.", locale);

        // Clear Run User Information
        loginService.userInfoClear();

        // System Information Settings
        EnvironmentInfo = new EnvironmentInfo();
        model.addAttribute("systemImage", environmentInfo.getSystemImage());
        model.addAttribute("systemName", environmentInfo.getSystemName());

        String wView = "Login";


        returnwView;

    }

    @RequestMapping(value="/", method=RequestMethod.POST)
    public String postLogin(@RequestParam("userid") String pUserId,
                             @RequestParam("password") String password,
                             Locale locale,
                             Model model) {

        try{

            logger.info("Login VikingEgg(LoginPOST) The client locale is {}.", locale);


            String userId = pUserId;
            String pass = password;

            String retForm="";

            // Clearing Input Error Messages
            model.addAttribute("errorMessage","");

            retForm="/";


            loginService.GetUserInfo(userId, pass);


            String ErrMsg = loginService.UserIDCheck();

            if(ErrMsg==""){

                // menu
                retForm = loginService.getMenu();


            } else {

                // input error
                model.addAttribute("errorMessage",ErrMsg);
                logger.info("nextMenu:"+retForm);

                retForm="/";


            }

            // retForm="forward:"+"AMenuController";
            logger.info("Login VikingEgg(NextMenu)="+retForm, locale);


            returnRetForm;


        }catch(Exceptione){

            logger.info("Login (POST)" + e.toString(), locale);


            return '';
        }


    }

}

<Control class for menu transitions from login>

package jp.vikingeg.VESales.control;

import java.io.IOException;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.announcement.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.announcement.RequestMapping;
import org.springframework.web.bind.announcement.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import jp.vikingegg.VESales.common.EnvironmentInfo;
import jp.vikingegg.VESales.common.GlobalConst;
import jp.vikingegg.VESales.service.AMenuservice;

@ Controller
public class AMenuController {

    private static final logger logger = LoggerFactory.getLogger(AMenuController.class);

    @Autowired
    private AMenuservice amenuService;

    @RequestMapping(value="/AMenu", method=RequestMethod.GET)
    public String getAMenu(Local locale, Model model) rows IOException {

        logger.info("AMenu(GET) The client locale is {}.", locale);

        try{

            logger.info("AMenu(GET)AMenuGET", locale);


            // System Information Settings
            EnvironmentInfo = new EnvironmentInfo();
            model.addAttribute("systemImage", environmentInfo.getSystemImage());
            model.addAttribute("systemName", environmentInfo.getSystemName());

            String wView = GlobalConst.cnsMenuAdmin;
            returnwView;

        }catch(Exceptione){

            logger.info("AMenu(GET)Error{"+e.toString()+"}", locale);

            String wView = GlobalConst.cnsLogin;
            returnwView;

        }

    }

    @RequestMapping(value="/AMenu", method=RequestMethod.POST)
    publicModelAndView postAMenu(Locale locale, Model model) {

        ModelAndView wView = new ModelAndView (GlobalConst.cnsMenuAdmin);
        returnwView;


    }

}

<Menu JSP>

<%@tagliburi="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page session="false" language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

        <title>${systemName} (Administrator Menu) </title>

        <!--Bootstrap CSS-->
        <link href="<c:url value="/resources/css/comm/bootstrap/bootstrap.min.css"/>"rel="stylesheet"media="screen">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <!--Full Screen Common Style-->
        <link href="<c:url value="/resources/css/comm/projectcomm/comm.css"/>"rel="stylesheet"media="screen">

        <!--- ADMIN Menu Screen Style-->
        <link href="<c:url value="/resources/css/AMenu.css"/>"type="text/css"rel="stylesheet"media="screen">


        <!---JQuery-->
        <script type="text/javascript" src="<c:url value="/resources/js/comm/jquery/jquery.min.js"/>">>/script>;

        <!--Bootstrap-->
        <script type="text/javascript" src="<c:url value="/resources/js/comm/bootstrap/bootstrap.min.js"/>"></script>


    </head>
    <body>

           <div class="row">
               <div class="col-sm-2col-md-2col-lg-2">
                   <img class="profile-img" src="<c:url value="${systemImage}"/>" alt=">
            </div>
               <div class="col-sm-10col-md-10col-lg-10">
                <font>${systemName1}</font>
            </div>
        </div>
        <form id="AMenu" name="FormAMenu" method="post">
            <div class="center-block">
                <div class="row">
                    <div class="col-sm-12col-md-12col-lg-12">
                        <ulid="dropmenu">
                          <li><a href="">Logout</a>
                          </li>
                          <li><a href="#">System Management</a>
                            <ul>
                              <li><a href="SystemEnv">System Environment</a></li>
                              <li><a href="#">Batch Scheduler</a></li>
                              <li><a href="#">Numbering Management </a></li>
                              <li><a href="#">Error Message Management </a></li>
                              <li><a href="#">Backup</a></li>
                            </ul>
                          </li>
                          <li><a href="#">User Management</a>
                            <ul>
                              <li><a href="#">Company Registration</a></li>
                              <li><a href="#">Organization Registration</a></li>
                              <li><a href="#">Employee User Registration</a></li>
                            </ul>
                          </li>
                          <li><a href="#">Statistics Processing </a>
                            <ul>
                              <li><a href="#">Access Analysis </a></li>
                            </ul>
                          </li>
                          <li><a href="#">Backup</a>
                            <ul>
                              <li><a href="#">Data Backup </a></li>
                              <li><a href="#">Save Environment</a></li>
                            </ul>
                          </li>
                        </ul>
                    </div>
                </div>
              </div>
            <div class="center-block">
                <div class="row">
                </div>
            </div>

        </form>

    </body>
</html>

java spring

2022-09-30 19:28

1 Answers

If you specify a string in the controller return value, you typically specify the path of View.

If you want to transition from one controller to another, use the forward.
To use forward, add forward: to the return string.

The path to getAMenu() in the AMenuController class is /AMenu in RequestMapping, so if you want to transition here, use forward:/AMenu as the return value.

However, if you use forward, the URL path displayed in the browser will be the original controller path (/ in this case).

If you want the URL displayed in your browser to be the path of the destination controller, use redirect in redirect:.


2022-09-30 19:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.