【问题标题】:Move a web app project from eclipse to tomcat standalone将 Web 应用程序项目从 Eclipse 移动到独立的 tomcat
【发布时间】:2014-11-27 03:14:38
【问题描述】:

你能帮我把一个 web 应用程序从 eclipse 部署到 tomcat 独立 我有一个在上下文路径“localhost:8080”上运行的网络应用程序,所有请求都将通过这样的主过滤器

@WebFilter("/*")
public class MainFilter implements Filter {

    /**
     * Default constructor. 
     */
    public MainFilter() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @see Filter#destroy()
     */
    public void destroy() {
        // TODO Auto-generated method stub
    }

    /**
     * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
     */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;

        String path = req.getRequestURI();
        request.setAttribute("uri", path);

        if( path.contains("/user")){
            if( path.contains("/post")){
                if( path.contains("/comment")){
                    req.getRequestDispatcher("/CommentServlet").forward(request, response);
                    return;
                }
                req.getRequestDispatcher("/PostServlet").forward(request, response);
                return;
            }

你能告诉我如何将它部署到 Tomcat 上,并与创建 web.xml 或配置任何东西相关。请在这里帮助我!

【问题讨论】:

  • 你在用maven吗?
  • @user1136403 我以前听说过,但我不确定。我是eclipse上的tomcat插件

标签: java eclipse tomcat filter


【解决方案1】:

如果您不使用 maven,请生成您的项目 war 文件,然后转到您的 webapp 目录,该目录位于 tomcat 文件夹下。如果您在此处使用 Windows C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps 复制战争文件,则可能是这样的。然后在 bin\ 下使用 startup.bat 启动你的 tomcat。这是没有 Maven 的老派方法。看看和研究一下 maven。

【讨论】:

  • 是的!我也这样做了,但它只是没有通过过滤器 ex:当我输入 localhost:8080/blog/welcome.html 它会运行,但如果 url 不匹配任何文件,它会 404?你能告诉我更多细节吗
【解决方案2】:

是的,我完成了!如果其他人看到就在这里发帖

我添加了一个这样的 web.xml 文件 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<filter>
    <filter-name>MainFilter</filter-name>
    <filter-class>MainFilter</filter-class>
    <init-param>
        <param-name>sleep-time-in-seconds</param-name>
        <param-value>10</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>MainFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
    <welcome-file>welcome.html</welcome-file>
</welcome-file-list>

然后将我的 web 导出到 webapps 文件夹中的 war 文件并更改为 ROOT.war 注意:我的 MainFilter 在默认包中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 2010-10-27
    • 2010-10-14
    • 2012-08-12
    • 2023-04-02
    • 2014-02-20
    • 1970-01-01
    相关资源
    最近更新 更多