简体   繁体   English

Java Web应用程序仅在Netbeans中运行

[英]Java web app only working in Netbeans

I am working on a Spring web app and everything works perfectly when i run it from netbeans. 我正在使用Spring Web应用程序,当我从netbeans运行它时,一切都可以正常运行。 My project is completely annotation based, the context.xml file is empty and there are no other XML files to speak of. 我的项目完全基于注释,context.xml文件为空,没有其他XML文件可说。 The war file resulting from the build process deploys fine under the tomcat manager webpage and i'm able to access the login page. 由构建过程产生的war文件可以在雄猫管理器网页下很好地部署,并且我能够访问登录页面。 As soon as the login button is pressed, what would normally be a redirection to the home page is not happening. 按下登录按钮后,通常不会重定向到主页。 One thing I am noticing is that when i click on my app in tomcat manager i am brought to localhost:8080/MDHIS_WebClient which correctly displays the login page. 我注意到的一件事是,当我在tomcat管理器中单击我的应用程序时,我被带到localhost:8080 / MDHIS_WebClient,它将正确显示登录页面。 As soon as i hit login, it gives me a 404 error with URL localhost:8080/login which is the name of the post method in my main controller that does the login process (notice the webapp name not in the URL anymore). 一旦我登录,它就会给我一个404错误,URL localhost:8080 / login,这是我执行登录过程的主控制器中post方法的名称(请注意,Web应用程序名称不再位于URL中)。 No matter what i manually enter in the URL bar, known valid URLs, i never get an actual page and it looks like the login process is not even happening. 无论我手动在URL栏中输入什么(已知有效的URL),我都永远不会得到实际的页面,并且看起来登录过程甚至没有发生。 I have looked at all the Tomcat logs and there are no errors logged whatsoever. 我已经查看了所有Tomcat日志,并且没有记录任何错误。 I did read other posts but i dind't find a similar set of symptoms. 我确实读过其他文章,但没有发现类似的症状。 I am completely baffled by this one and I don't even see what relevant code i could post here. 我对此完全感到困惑,我什至看不到我可以在此处发布的相关代码。

If you have ever encountered this issue please help. 如果您遇到此问题,请提供帮助。

Regards 问候

* EDIT * *编辑*

This is my onStartup() method in my ApplicationInitializer class : 这是我的ApplicationInitializer类中的onStartup()方法:

@Override
public void onStartup(ServletContext container) throws ServletException 
{
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(ApplicationConfiguration.class);
    ctx.setServletContext(container);
    ContextLoaderListener contextLoaderListener = new ContextLoaderListener(ctx);
    ctx.getServletContext().addListener(contextLoaderListener);
    ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
}

Finally found the answer in a post on another forum : 终于在另一个论坛的帖子中找到了答案:

In your tomcat's conf/server.xml add: 在您的tomcat的conf / server.xml中添加:

<Context path="" docBase="NameOfYourWar" debug="0" reloadable="true"></Context>

in your server.xml file before ending tag 在您的server.xml文件中,结束标记之前

This will ensure your context being loaded without the war file name in the root. 这将确保您的上下文被加载而根目录中没有war文件名。 Alternative is rename your war file to ROOT.war and delete the ROOT folder in webapps, and deploy your own ROOT.war file. 另一种方法是将war文件重命名为ROOT.war,然后删除webapps中的ROOT文件夹,然后部署自己的ROOT.war文件。

I can confirm this works! 我可以确认这项工作!

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

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