简体   繁体   English

将Web应用程序项目从Eclipse移至tomcat独立

[英]Move a web app project from eclipse to tomcat standalone

Can you help please me with deploy an web app from eclipse to tomcat standalone I have a web app run on context path "localhost:8080" and all request will go through a Main Filter like that 您能帮我从eclipse到tomcat独立部署Web应用程序吗?我有一个在上下文路径“ localhost:8080”上运行的Web应用程序,所有请求都将通过这样的主过滤器

@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;
            }

Could you tell me how to I can deploy it on tomcat with anything relate like create web.xml or config anything. 您能告诉我如何将它与诸如create web.xml或config config之类的任何内容一起部署在tomcat上。 Please help me here ! 请在这里帮助我!

If you are not using maven, generate your projects war file and then go to your webapp directory which is under the tomcat folder. 如果您不使用maven,请生成项目war文件,然后转到tomcat文件夹下的webapp目录。 It might be something like that if you are using windows C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\webapps copy war file here. 如果您正在使用Windows C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\webapps在此处复制war文件,则可能是类似的内容。 Then under the bin\\ start your tomcat with startup.bat. 然后在bin \\下,使用startup.bat启动您的tomcat。 This is old school method without maven. 这是没有行家的老派方法。 Take a look and research about maven. 看一下有关Maven的研究。

yes I'm done ! 是的,我完成了! just post here for if other people look at 只是在这里张贴,以便其他人看看

I was add a web.xml file like that http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 我添加了一个像http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd“>这样的web.xml文件

<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>

And export my web to war file in webapps folder and change to ROOT.war notice : my MainFilter in default package 并将我的网站导出到webapps文件夹中的war文件中,并更改为ROOT.war注意:默认包中的MainFilter

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

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