大家好,
  我现在用struts2+tomcat+pluto总是不能显示portlet程序,但如果不用struts2,直接用servlet就可以,下面是代码,请问哪里有问题?谢谢!
如果用struts2,是不是要在web.xml中配置filter?web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
        "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
        <display-name>Struts2TestPortlet</display-name>
        <filter>
                <filter-name>Struts2 Filter</filter-name>
                <display-name>Struts2 Filter</display-name>
                <description>Struts2 Filter</description>
                <filter-class>
                        org.apache.struts2.dispatcher.FilterDispatcher
                </filter-class>
        </filter>
        <filter-mapping>
                <filter-name>Struts2 Filter</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>
        <welcome-file-list>
                <welcome-file>index.html</welcome-file>
                <welcome-file>index.htm</welcome-file>
                <welcome-file>index.jsp</welcome-file>
                <welcome-file>default.html</welcome-file>
                <welcome-file>default.htm</welcome-file>
                <welcome-file>default.jsp</welcome-file>
        </welcome-file-list>
</web-app>
 
portlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app
        xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
        version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd 
        http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
        id="com.ibm.faces.portlet.FacesPortlet.3ccbdcb861">
        <portlet>
                <portlet-name>Struts2 Test Portlet</portlet-name>
                <display-name>Struts2 Test Portlet</display-name>
                <portlet-class>
                        org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher
                </portlet-class>
                <init-param>
                        <name>viewNamespace</name>
                        <value>/view</value>
                </init-param>
                <init-param>
                        <name>editNamespace</name>
                        <value>/edit</value>
                </init-param>
                <init-param>
                        <name>helpNamespace</name>
                        <value>/help</value>
                </init-param>
                <init-param>
                        <name>defaultViewAction</name>
                        <value>view</value>
                </init-param>
                <init-param>
                        <name>defaultEditAction</name>
                        <value>edit</value>
                </init-param>
                <init-param>
                        <name>defaultHelpAction</name>
                        <value>help</value>
                </init-param>
                <supports>
                        <mime-type>text/html</mime-type>
                        <portlet-mode>view</portlet-mode>
                        <portlet-mode>edit</portlet-mode>
                        <portlet-mode>help</portlet-mode>
                </supports>
                <portlet-info>
                        <title>Struts2 Test Portlet</title>
                        <short-title>Struts2 Test Portlet</short-title>
                        <keywords>Struts2 Test Portlet</keywords>
                </portlet-info>
        </portlet>
</portlet-app>
 
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
        <include file="struts-portlet-default.xml" />
        <package name="view" extends="struts-portlet-default"
                namespace="/view">
                <action name="view">
                        <result>/WEB-INF/jsp/input.jsp</result>
                </action>
                <action name="login" class="struts2TestPortlet.action.Login">
                        <result name="input">/WEB-INF/jsp/input.jsp</result>
                        <result name="success">/WEB-INF/jsp/success.jsp</result>
                        <result name="fail">/WEB-INF/jsp/fail.jsp</result>
                </action>
        </package>
        <package name="edit" extends="struts-portlet-default"
                namespace="/edit">
                <action name="edit">
                        <result>/WEB-INF/jsp/edit.jsp</result>
                </action>
        </package>
        <package name="help" extends="struts-portlet-default"
                namespace="/help">
                <action name="help">
                        <result>/WEB-INF/jsp/help.jsp</result>
                </action>
        </package>
</struts>
 
struts2 action: Login.java
 
package struts2TestPortlet.action;
 
import com.opensymphony.xwork2.ActionSupport;
 
public class Login extends ActionSupport {
        String username;
 
        String password;
 
        public String getPassword() {
                return password;
        }
 
        public void setPassword(String password) {
                this.password = password;
        }
 
        public String getUsername() {
                return username;
        }
 
        public void setUsername(String username) {
                this.username = username;
        }
 
        public String execute() throws Exception {
                System.out.println("execute");
                if (username.equals("yanzhid") && password.equals("pwd")) {
                        return "success";
                } else {
                        return "fail";
                }
        }