如何在Team City插件开发JSP中处理表单提交

时间:2019-02-22 17:25:43

标签: java jsp teamcity

我正在学习如何使用Java JSP编写TeamCity插件。

我想要一种除文本信息之外的表格,并将其用于数据处理。

我面临的问题是,当我单击“提交”按钮时,我得到了404。

控制器

public class ServerConfigGeneralController extends BaseFormXmlController {
      public ServerConfigGeneralController(@NotNull SBuildServer server,
                                           @NotNull WebControllerManager webControllerManager) {
        super(server);
        webControllerManager.registerController("/admin/", this);
      }

      @Override
      @Nullable
      protected ModelAndView doGet(@NotNull final HttpServletRequest request, @NotNull final HttpServletResponse response) {
          System.out.println("######In Model and View########");
        return null;
      }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response, Element xmlResponse) {
        // TODO Auto-generated method stub

        System.out.println("######In Do Post########");

    }

}

Jsp

<html>
    <h1>Consul Key Value settings</h1>
   <body>

      <form action = "ServerConfigGeneralController" method = "post">
         URL: <input type = "text" name = "url">
         <br />
         Port: <input type = "text" name = "port" />
         <input type = "submit" value = "Submit" />
      </form>

   </body>
</html>

xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
       default-autowire="constructor">

       <bean class="com.demoDomain.teamcity.demoPlugin.AppServer"></bean>
       <bean id="MyListener" class="com.demoDomain.teamcity.demoPlugin.MyListener"></bean>
       <bean id="TestAdminPage" class="com.demoDomain.teamcity.demoPlugin.TestAdminPage"></bean>
       <bean id ="ServerConfigGeneralController" class="com.demoDomain.teamcity.demoPlugin.ServerConfigGeneralController"></bean>
</beans>

我希望可以调用Post并在团队城市服务器控制台上打印出Sys。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

设法解决。

我需要执行表单操作以匹配控制器注册的URL。

<form action = "/admin/consul.html" method = "post">

在控制器中

manager.registerController("/admin/consul.html", this);

多谢