0

I want to ask how to deploy application in application server such as tomcat, Im using SpringMVC and run in idea using jetty, when I run in localhost:8080, it works, but when deploy using war in tomcat, the url will be like localhost:8080/app, the login is shown, but when controller calling new page it failed, please help me

the step I reproduce Appfuse is:

  1. Following http://appfuse.org/display/APF/AppFuse+QuickStart, run the generated mvn command
  2. mvn appfuse:full-source
  3. until this step, when I run "mvn jetty:run", it run OK, either I create war using "mvn jetty:run-war" and there is demo.war and I deploy to tomcat still OK
  4. I add some menu and pages, one of them is accountStatement.jsp and accountStatementResult.jsp with their controller. the accountStatement page choose period date and then after click ext button there will be result of accountStatement.
  5. the result of accountStatement.jsp is like: accountStatement You can try it in this link, I already deploy in amazonaws.ec2 server: http://ec2-54-175-88-32.compute-1.amazonaws.com:8080/demo/ username is user/user or admin/admin

  6. I use submit button, and inside the AccountStatementController.java some of the important code is like below:

    public AccountStatementController() {
    setCancelView("redirect:home");
    setSuccessView("/accountStatementResult");
    

    }

    @RequestMapping(method=RequestMethod.POST) public String onSubmit( @RequestParam(value = "periodType", required = false) final String periodType, @RequestParam(value = "datepickerFrom", required = false) final String datepickerFrom, @RequestParam(value = "datepickerUntil", required = false) final String datepickerUntil, @RequestParam(value = "months", required = false) final String months, final RedirectAttributes redirectAttributes, final HttpServletRequest request) throws Exception { String period = datepickerFrom + " - " + datepickerUntil; if (periodType.equals("monthly")) { period = months; }

    redirectAttributes.addFlashAttribute("period", period);
    
    return getSuccessView();
    

    }

  7. When I run from intellij Idea using "mvn jetty:run" it run perfect, after push the submit button, it will redirect to accountStatementResult page.

  8. But when I create demo.war and deploy in tomcat it run error, after accountStatement page and push button, the result is error.

  9. I think the error is in the urlwriter.xml, I ever made application using appfuse 1.9 in my previous office, and now I want to create and sell my own application using appfus. Thank you so much for your help.

I also create the repository of the source on google code, you can ask me the password if you need to see the full code. Thank you

Imam Baihaqi
  • 175
  • 1
  • 10
  • Did you figure out the cause of this? – Matt Raible Jan 14 '15 at 17:55
  • Not yet Matt, when I run as http://appfuse.org/display/APF/AppFuse+QuickStart, and run it using mvn jetty:run, it success in http://localhost:8080. But when I deploy in tomcat as webapps/demo.war when I call a page from controller, it always redirect into root directory rather than root/demo. When I see the localhost_acces_log in tomcat/logs folder, the problem is URL always go to root directory not in root/demo directory: "POST /accountStatement HTTP/1.1" 404 - it should go to: "POST /demo/accountStatement HTTP/1.1" 404 - – Imam Baihaqi Jan 18 '15 at 22:24
  • I already deploy the application in amazone ec2 in this link: http://ec2-54-175-88-32.compute-1.amazonaws.com:8080/demo when we go to menu: Informasi Rekening -> Mutasi Rekening and push submit button, it will error, when we run in local using mvn jetty:run it run perfectly – Imam Baihaqi Jan 18 '15 at 23:54
  • I think the problem is in urlrewrite.xml, when I change the pom.xml, / into /prototype, every request will error, and the log said: No mapping found for HTTP request with URI [/prototype/app/account/accountStatement] in DispatcherServlet with name 'dispatcher' the url shold be /app/prototype/account it rewrite as /prototype/app/account – Imam Baihaqi Jan 19 '15 at 23:40
  • You might try adding use-context="true" to the urlrewrite element. http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.0/index.html#configuration – Matt Raible Jan 20 '15 at 01:04
  • after I add use-context="true", the result is: The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. – Imam Baihaqi Jan 21 '15 at 23:14
  • If you can provide the steps to reproduce on a new AppFuse Spring MVC app, I'd be happy to see if I can reproduce the problem. Editing your original question might be the easiest way to specify the steps. – Matt Raible Jan 22 '15 at 15:06
  • I already edit the question Matt, thank you so much for helping – Imam Baihaqi Jan 22 '15 at 16:49
  • If you can send me a zip file of your project, I can try to reproduce and see what the difference between jetty:run and running is. However, you can also create a src/main/webapp/META-INF/context.xml file with the following. This will mount your WAR to the root context. – Matt Raible Jan 23 '15 at 17:19
  • https://www.dropbox.com/s/cs64v9p2sp877x5/refresh.zip that the zip of the project, I don't know the email so I put on dropbox, I already add context.xml but still get the same error, – Imam Baihaqi Jan 24 '15 at 06:16

1 Answers1

1

In accountStatement.jsp, change the "action" of your form to be one of the following:

<form:form commandName="account" method="post" action="accountStatement" id="accountForm">

This produces a relative URL to the controller that you want to submit to. Or you can specify an absolute URL:

<form:form commandName="account" method="post" action="${ctx}/account/accountStatement" id="accountForm">

I tested and made sure both solutions worked.

Matt Raible
  • 8,187
  • 9
  • 61
  • 120