in Programming

Eclipse Indigo运行Struts2的几个问题

小结

在Eclipse Indigo的集成环境中运行Apache Tomcat v7.0和Struts2,碰到几个问题,找不到Tomcat v7.0, Java Compiler不匹配,找不到Run at Server,等等,进行了解决。

问题及解决

进入Tomcat管理界面

进入Tomcat管理界面需要访问地址:http://localhost:8080/manager/
用户名密码是在以下配置文件里配置的: C:\apache-tomcat-7.0.109\conf\tomcat-users.xml

<role rolename="manager-gui"/>
<role rolename="admin"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="tomcat"/>
<role rolename="manager"/>
<user username="tomcat" password="xxxxxx" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script,tomcat,manager,admin"/>

在这里,用户名,密码是:username="tomcat" password="xxxxxx"

配置StrutsTutorial项目

在Tomcat的配置文件中C:\apache-tomcat-7.0.109\conf\server.xml进行配置:

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
<Context path="/StrutsTutorial" reloadable="true" docBase="C:\Users\HuiLin_Xiong\workspace\StrutsTutorial" workDir="C:\Users\HuiLin_Xiong\workspace\StrutsTutorial\work" />


      </Host>

Eclipse error: Target runtime Apache Tomcat v7.0 is not defined

参考Eclipse error: Target runtime Apache Tomcat v7.0 is not defined , Eclipse返回找不到Tomcat v7.0的错误。这里需要安装 JST Server adapters,在Help--> Eclipse Marketplace查找JST Server adapters进行安装,就可以找到Project FacetApache Tomcat v7.0进行配置,这个问题就解决了。

Java compiler level does not match

参考Java compiler level does not match the version of the installed Java project facet
Properties --> Compiler Compliance Level设置正确的JDK版本号,这个问题解决。

“Servers” view missing from Eclipse Indigo

参考“Servers” view missing from Eclipse Indigo

到这里Window > Show View > Other...进行设置,即可解决。

Struct2的Struct.xml的设置

以下的Struct.xml的设置:

    <package name="login" namespace="/login" extends="struts-default">
        <action name="toLogin">
            <result>/pages/login.jsp</result>
        </action>

        <action name="doLogin" class="cn.hxex.struts.login.action.LoginAction">
            <result name="input">/pages/login.jsp</result>
            <result name="error">/pages/login.jsp</result>
            <result name="success">/pages/loginsuccess.jsp</result>
        </action>
    </package>

Tomcat的服务器运行起来以后,在地址栏里输入:http://127.0.0.1:8080/StrutsTutorial/login/toLogin.action即可运行相应的程序。

也就是以下格式:http://IP:port/Web应用名称/namespace/Action名字.action
注意,根据前面的配置在C:\Users\HuiLin_Xiong\workspace\StrutsTutorial\work里的各种文件需要配置好。

参考

Eclipse error: Target runtime Apache Tomcat v7.0 is not defined
Java compiler level does not match the version of the installed Java project facet
“Servers” view missing from Eclipse Indigo
How do I kill the process currently using a port on localhost in Windows?

Write a Comment

Comment