十一月 2009


javaee02 十一 2009 10:47 下午

开发环境

JDK5,发布环境WAS6.1.0.21

Struts2,Spring2,hibernate3.1

问题描述

1)struts.xml中没有配置default-action-ref

2)web.xml中使用s2的过滤器过滤/*,而不是*.action

3)设置了welcomefile为index.jsp,index.jsp再导向到Index.action。

[09-10-30 15:42:37:982 CST] 00000037 Dispatcher    W com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn Could not find action or result
There is no Action mapped for namespace / and action name . – [unknown location]

发布到WAS下总是提示不能导向的首页的Index.action,应该

http://server:port/appContext

http://server:port/appContext/

这两个urlpatten优先映射给s2的过滤器了。

首先想到的解决办法是将web.xml中的welcome-file设置为Index.action,经测试这种方法是行不通的,welcome-file必须是一个实在的文件而不是一种映射,这点可能跟具体的容器实现策略相关的,在Tomcat或者WL下可能是生效的,但在WAS下是行不通的。经过研究和测试我最终找到了解决方案是自行开发一个过滤器名为WelcomeFileFilter,此过滤器优先于s2的过滤器,拦截请求的URI,分析请求的URI是否相对于appContex是根目录,是的话,则应答为导向到一个具体的首页如Index.action。否则的话继续下一个过滤器。Filter的先后顺序是从web.xml的从上到下开始执行的。固将此过滤器声明于s2的过滤器之上并将其影响范围设置为/*,即可正常的在WAS下敲入首页时导向到Index.action了。WAS对web.xml的书写规范是比较苛刻的。

附WelcomeFileFilter.java

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

public class WelcomeFileFilter implements Filter {
public void destroy() {
indexFile = null;
}

private String indexFile;

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
//String servletPath = httpServletRequest.getServletPath();
String contextPath = httpServletRequest.getContextPath();
String requestURI = httpServletRequest.getRequestURI();
//System.out.println(requestURI);
if (contextPath.equalsIgnoreCase(requestURI) || (contextPath+”/”).equalsIgnoreCase(requestURI)) {
String url = “”;
if(indexFile.startsWith(“/”)){
url = contextPath + indexFile;
}else{
url = contextPath +”/” +indexFile;
}
httpServletResponse.sendRedirect(url);
} else {
chain.doFilter(request, response);
}
}

public void init(FilterConfig arg0) throws ServletException {
indexFile = “Home.action”;
String x = arg0.getInitParameter(“indexFile”);
if (StringUtils.isNotBlank(x)) {
indexFile = x;
}
}

}

javaee and websphere02 十一 2009 10:12 下午

今天测试开发机器的机器名被网管给改了,导致之前安装的WAS概要的服务无法启动了,环境是Win2003Server,WAS6.1.0.21版本。

在网上找了些资料,解决此问题有两种办法

1)将WAS的概要文件和主机名解除耦合,使用IP代替,没测试过

2)修改WAS的概要文件的配置文件,可借助脚本

在网上找到两个非常有效的帖子

http://www.webspherechina.net/club/archiver/tid-9377.html

http://www.ibm.com/developerworks/websphere/library/samples/SampleScripts.html

具体操作的步骤
1)下载ConfigScripts.zip,并解压缩到D:\IBM\WebSphere\AppServer\bin目录下
2)进入cmd命令行,敲如下命令
ws_ant -profileName Dmgr01 -buildfile exportImpor
t.xml -DstartManager=yes -DoldHostName=old -DnewHostName=new changeHostName
然后是命令的一系列输出
最后输出
BUILD SUCCESSFUL
Total time: 39 seconds

表示这个DM的主机名的配置已经被更改了,至于NodeAgent的服务跟如上命令差不多,只是把-DstartManager=yes这个参数去掉就可以了

IHS的配置也要跟着更改一下,我索性把原有的webserver删除重新搞了一个全新的webserver,再进行生成插件和传播插件。

« 上一页