0

我需要继续一个现有的模板项目,你可以在这里找到:

http://soft.vub.ac.be/soft/_media/edu/aosd/bankingwebstudent.zip

到目前为止,我已经实现了数据和服务层,但是你如何运行这个项目?因为据我所知没有主要类型......我尝试通过右键单击运行banking.deploy.xml - >在服务器上运行 - > tomcat 6.0,但这没有用。

4

3 回答 3

2

从您附加的任何文件来看,它看起来不像是一个 maven 项目,因为它缺少一个 pom.xml 文件。如果你想将你的项目转换成maven项目,只需将项目导入IDE(可能是Eclipse)作为一个普通的java web应用项目,然后右键添加一个maven pom.xml文件。(请安装maven在执行此操作之前为 Eclipse 插件)。然后您可以转到项目主文件夹,并在命令提示符下,将您的项目构建为:

mvn 干净安装

或者

mvn clean install -Dmaven.test.skip -DskipTests(如果您想跳过任何测试)。

构建项目后,从目标目录复制 war 文件,并将其复制到 ApacheTomcat 的 webapps 文件夹中。

由于您的 web.xml 中有此条目:

<servlet>
    <servlet-name>BankingWeb</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

默认情况下,Spring 会查找名为 BankingWeb-servlet.xml 的配置文件,该文件位于您的应用程序中,您在其中导入了用于配置控制器的 xml 文件。(即,banking.web.controller.xml)。

现在,假设您触发以下网址:

http://localhost:8080/BankingWeb/login.htm

流程是这样的:

web.xml -> BankingWeb-servlet.xml -> LoginController -> loginSuccess.jsp。

但在所有这些发生之前,由于 web.xml 中提到了一个过滤器,所以过滤器将首先执行。

此外,由于 web.xml 文件中有一个 ContextLoadListener 属性,Spring 将搜索一个名为 applicationContext.xml 的文件,您将在该文件中导入banking.deploy.xml。这就是基本流程的发生方式。必须说,现在是升级到 Spring 3.0 的时候了,而且到目前为止,您在整个项目中还没有使用太多 Spring。

于 2012-12-13T14:46:09.800 回答
0

假设您的 Spring 设置是连贯的并且您web.xml包含相关的RequestContextListener,例如。

<web-app ...>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
</web-app>

您可以使用 Jetty 编写一个小类Launcher来启动应用程序:

public class Launcher
{
    public static void main( String[] args ) throws Exception
    {
        Server jettyServer = new Server();
        SocketConnector conn = new SocketConnector();
        conn.setPort( 8080 );
        jettyServer.setConnectors( new Connector[]{ conn } );
        WebAppContext context = new WebAppContext();
        context.setContextPath( "/" );
        context.setWar( "src/main/webapp" );
        jettyServer.setHandler( context );
        jettyServer.start();
    }
}

你至少需要这个依赖:

<dependency>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty</artifactId>
    <version>6.1.9</version>
</dependency>

还有其他人,如果你需要的话。JSP 和/或 JNDI 能力。

希望有帮助。

于 2012-12-13T10:22:24.100 回答
0

Spring 是一个框架,它可以帮助您管理您的 servlet。您需要从您的项目中创建一个war 文件并将其部署到tomcat 中。

您需要按照以下说明编辑 web.xml(在 tomcat 中):

http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch16s02.html

之后,对 tomcat 的 HTTP 请求将被重定向到 spring servlet

于 2012-12-13T10:16:12.253 回答