大家好,
我现在用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";
}
}
我现在用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";
}
}
解决方案 »
- SSH 中用iterator取得业务层list疑问
- jsp页面中中文乱码问题(不是动态数据乱码,而是本来页面中的"中文提示"变成乱码)
- clob blob 问题
- contentType都有哪些值啊?
- 建数据库的脚本
- js comfirm中插入checkbox
- java jsp select级联问题
- 访问TOMCAT 8080端口,被要求输入xdb验证,然后报Unauthorized错误?
- 哪儿有 JSP 详细的学习资料? 书籍版本的, 网上找的都是零散的, 不好学习.
- session中的setAttribut方法和getAttributName()方法有什么用,大家帮忙,具体一点
- 复选框问题 在线等 急!!!
- 发个未指定格式的日期字符串转日期类型的代码!顺便散个分!
顺便问一下,pluto是什么东东?