Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用相同的值返回到SpringMVC中的相同JSP页面_Spring_Jsp_Spring Mvc - Fatal编程技术网

如何使用相同的值返回到SpringMVC中的相同JSP页面

如何使用相同的值返回到SpringMVC中的相同JSP页面,spring,jsp,spring-mvc,Spring,Jsp,Spring Mvc,请帮我做这个。下面是我的LoginController类,我从JSP传递用户名和密码,然后在不同的JSP页面中验证并显示用户名的待办事项列表 这是我的密码 LoginController.class @RequestMapping(value = "/loginvalidate") public String validatelogin(LoginForm request, ModelMap map) throws Exception { String userName = re

请帮我做这个。下面是我的LoginController类,我从JSP传递用户名和密码,然后在不同的JSP页面中验证并显示用户名的待办事项列表

这是我的密码

LoginController.class

  @RequestMapping(value = "/loginvalidate")
  public String validatelogin(LoginForm request, ModelMap map) throws Exception {
    String userName = request.getUserName();
    sessionUser.setUserName(userName);
    map.addAttribute("user", sessionUser.getUserName());
    map.addAttribute("dateTime", sessionscopebillingdata.getDate());
    System.out.println("username from the controller class " + sessionUser.getUserName());
    List result = loginservice.ValidateLogin(request);
    map.addAttribute("ToDoList", result);
    return "UserToDoList";
 } 
@RequestMapping(value = "/adduser")
public String adduser(LoginForm request) throws Exception {
    String result = loginservice.adduser(request);
    return "/Adduser";
 }
这是我的UserToDoList.jsp

<html>
<head>
    <title>Home</title>
<div class="inset">
    <%=session.getAttribute("dateTime")%>
    <h2> TO DO LIST </h2>        
    <%=session.getAttribute("user")%>
    <link href="style.css" rel="stylesheet" type="text/css"/>
</head>    
<body>
    <form action="logout" method="POST">
        <button type="submit">Logout</button>    
    </form>        

    <form name="Add" action="Adduser" method="post">
        <button type="submit">ADD</button> 

    </form>
    </link>
    <form:form>

        <c:if test="${not empty ToDoList}">

            <table>

                <tr><th>LOGIN ID</th>
                    <th>LAST UPDATE BY</th>
                    <th>TRANSACTION TYPE</th>
                    <th>STATUS</th>
                </tr>    
                <c:forEach var="item" items="${ToDoList}">
                    <tr>   <td>${item[0]}</td>
                        <td>${item[1]}</td>
                        <td>${item[2]}</td>   
                        <td>${item[3]}</td>
                    </tr>
                </c:forEach>

            </table>

        </c:if>


    </form:form>

  </body>
  </html>
下面是id my bean以获取用户名

@Component
@Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)

public class BillingSessionScopeUser {

public String userName;

public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}
}


返回单击“添加”按钮时要显示的文件名。

我认为应该将登录阶段与todo列表提取明确分开。它可能看起来像:

@RequestMapping(value = "/loginvalidate")
public String validatelogin(LoginForm request, ModelMap map, Session session) throws Exception {
    String userName = request.getUserName();
    sessionUser.setUserName(userName);
    map.addAttribute("user", sessionUser.getUserName());
    map.addAttribute("dateTime", sessionscopebillingdata.getDate());
    System.out.println("username from the controller class " + sessionUser.getUserName());
    // BEGIN CHANGE
    List result = loginservice.getTodoList(userName);
    //END CHANGE
    map.addAttribute("ToDoList", result);
    return "UserToDoList";
}
然后在
adduser
POST
部分中,您可以:

@RequestMapping(value = "/adduser")
public String adduser(@ModelAttribute LoginForm request, ModelMap model) throws Exception {
    String result = loginservice.adduser(request);
    String userName = sessionUser.getUserName();
    List result = loginservice.getTodoList(userName);
    map.addAttribute("ToDoList", result);
    map.addAttribute("user", userName);
    map.addAttribute("dateTime", sessionscopebillingdata.getDate());
    return "UserToDoList"; // ensure correct name for view
 }
或者,您可以尝试从
sessionUser
(最终是其他会话范围的bean)重建
LoginForm
,比如
sessionRequest
,并直接使用:

List result = loginservice.ValidateLogin(sessionRequest);

您需要将
@ModelAttribute(“LoginForm”)
添加到
LoginForm
方法参数中。你不应该用它来传递信息。您已经有一个会话作用域对象,您应该在两个控制器中使用它。并且。。。什么是sessionUser?它是HttpSession的一部分吗?@M.Deinum谢谢,我已经完成了公共字符串验证登录(@ModelAttribute(“LoginForm”)LoginForm请求,ModelMap)是否正确?如何保持模型属性?基本上,当我从Adduser返回Adduser时,我想再次显示UserToDoList.jsp的相同视图method@SergeBallesta,我添加了bean类BillingSessionScopeUser.class,并在控制器类private BillingSessionScopeUser sessionUser中自动连接该类;并使用scope(“session”)SessionAttributes({“user”,“dateTime”})进行注释嗨,很抱歉,这是我的错误,我已返回了您所说的文件,但jsp中的列表仍然为空。@RequestMapping(value=“/adduser”@ModelAttribute(“roleId”)BillingSessionScopeUser BillingSessionScopeUser)如果需要密码,您将获得用户名值,然后,您应该在模型类BillingSessionScopeUser中声明approver和userRole,然后您将在上述行中获得类的对象中的所有值。您可以检查字符串userName=BillingSessionScopeUser.getUserName()您必须在map中添加结果,并且必须在jsp中访问结果。谢谢,在我分离了验证和待办事项列表方法之后,它可以工作了。
@RequestMapping(value = "/adduser")
public String adduser(@ModelAttribute LoginForm request, ModelMap model) throws Exception {
    String result = loginservice.adduser(request);
    String userName = sessionUser.getUserName();
    List result = loginservice.getTodoList(userName);
    map.addAttribute("ToDoList", result);
    map.addAttribute("user", userName);
    map.addAttribute("dateTime", sessionscopebillingdata.getDate());
    return "UserToDoList"; // ensure correct name for view
 }
List result = loginservice.ValidateLogin(sessionRequest);