简体   繁体   English

如何从SAPUI5控制器向Java Servlet发出POST请求?

[英]How to do a POST request from SAPUI5 controller to Java Servlet?

I have created a dynamic web project with a Tomcat 8.5 Server and then I created an index.html that do start my first view (a simple form for login). 我已经使用Tomcat 8.5服务器创建了一个动态Web项目,然后创建了一个index.html来启动我的第一个视图(一种简单的登录形式)。 When I click the button for login start function onPress: 当我单击登录启动功能按钮onPress时:

     onPress : function() {
          var user = this.getView().byId("userInput").getValue();
          var pwd = this.getView().byId("passwordInput").getValue();
          var request = {
                un : user,
                pw : pwd
            };
          $.post("LoginServlet", request, function() {
            alert("Ciao");
          });
      }

I want to pass user and pwd to this servlet (LoginServlet) 我想将用户名和密码传递给该servlet(LoginServlet)

public class LoginServlet extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {

    try {    
        UserBean user = new UserBean();
        user.setUserName(request.getParameter("un"));
        user.setPassword(request.getParameter("pw"));

        user = UserDAO.login(user);

        /*if (user.isValid()) {

            HttpSession session = request.getSession(true);
            session.setAttribute("currentSessionUser", user);
            response.sendRedirect("userLogged.jsp"); // logged-in page
        }else
            response.sendRedirect("invalidLogin.jsp"); // error page*/
    } catch (Throwable theException) {
        System.out.println(theException);
    }
  }
}

The error I am getting is: 我得到的错误是:

404 Not Found. 找不到404。 Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 说明:原始服务器找不到目标资源的当前表示,或者不愿意透露该资源的存在。 Message: /LOGIN_RACMET_UI5_DynamicWebProject/LoginServlet 消息:/ LOGIN_RACMET_UI5_DynamicWebProject / LoginServlet

I need that the frontend is developed in SAPUI5, so I can't use JSP, PHP, etc. 我需要前端是在SAPUI5中开发的,所以我不能使用JSP,PHP等。

The project is structured like this 该项目的结构类似于

When i do the call this is the result 当我打电话时这就是结果

I resolve it. 我解决了。 It's wrong the url 网址错误

$.post("LOGIN_RACMET_UI5_DynamicWebProject/LoginServlet", request, function() {
        alert("Ciao");
      });

This is right 这是对的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM