portal开发

xiaoxiao2026-05-24  17

一、Portlet中的资源处理 1、表单提交 <form name="form1" method="post" action="<portletAPI:createURI><portletAPI:URIAction name='<%=SourcePortlet.FORM_ACTION%>'/> 这样就指定了该页面提交的portlet,这么写就指定了该URL的命名空间,这里的SourcePortlet.FORM_ACTION对应SourcePortlet.java(是一个Portlet)中定义的常量: public static final String FORM_ACTION = "SourcePortletFormAction"; 如果是Struts的Portlet <html:form action="/logon.do" focus="username" urltype="return"></html:form> 这里的“/logon.do”对应Struts-config中的ActionMapping中的配置 urltype="return" 表明处理表单后,直接返回View 模式 2、图片、多媒体的插入 <img src=’<%= renderResponse.encodeURL(renderRequest.getContextPath() +"/images/earth.jpg")%>’alt="Earth" /> 或者 String imgURL= response.encodeURL("img/time.png"); <img src="<%=imgURL%>" <object classid=’<%=renderResponse.encodeURL(renderRequest.getContextPath() +"/audio/WakeUpSong.mp3")%>’type="audio/wav" width="300" height="18"> <param name="controls" value="smallconsole" valuetype="data"> <param name="autostart" value="true" valuetype="data"> <param name="controller" value="true" valuetype="data"> </object> 3、html/jsp/CSS/JS等文件的引入 java:String testURL = response.encodeURL(/html/test.htm); javascript:window.showModalDialog('<%=testURL %>',…………); <link rel="stylesheet" type="text/css" href="<%= portletResponse.encodeURL(basestyle.css)%>"> 4、javascript函数命名 function <%=portletResponse.encodeNamespace("Show_BlkBlackTab(BlkBlackTabid_num,BlkBlackTabnum)")%> 调用javascript function的组件 <a href="#" target="_self" οnclick="<%=portletResponse.encodeNamespace("Show_BlkBlackTab(1,"+i+")'")%>,">js函数调用</a> 5、超链接处理 Struts Portlet中 <%@ page language="java" import="com.ibm.wps.struts.common.PortletApiUtils" %> <% PortletApiUtils portletUtils = PortletApiUtils.getInstance(); %> <% if (portletUtils != null) { String url = "/target.jsp"; // add the module prefix to the url url = portletUtils.addModulePrefix(url, request); Object portletURI = portletUtils.createPortletURIWithStrutsURL(request, url); %> <a href="<%=portletURI.toString()%>">链接到指定页面</a> <% } %> 二、Portlet中的JSP 1、JSP中应只做展示的处理,不做业务逻辑处理,更不能进行数据库操作处理 2、非Struts Portlet的javabean 应该存储在session中,Struts中应该使用ActionForm进行数据传输。 3、JSP的注释 不允许使用<!-- --> 使用<%-- --%> 4、JSP中尽量使用JSTL或Struts标签 三、java开发中的异常处理 采用非强制异常处理,应该避免异常一层一层向上抛 避免在try块中堆集大量的不同类型,不同功能的代码 java中常见异常 1、空指针错误 java.lang.NullPointerException 使用基本的JAVA数据类型,变量的值要么已经是默认值,如果没有对其正常赋值,程序便不能通过编译,因此使用基本的JAVA数据类型(double,float,boolean,char,int,long)一般不会引起空指针异常。由此可见,空指针异常主要跟与对象的操作相关。 异常处理方式 1) 检查到异常出现,设置对象值为空字符串或一个默认值。 异常处理方式 2) 检测到异常出现,根本不执行某操作,直接跳转到其他处理中。 异常处理方式 3) 检查到异常出现,提示用户操作有错误。 2、格式化数字错误 java.lang.NumberFormatException JAVA无法将其转化为合适的数字,导致抛出java.lang.NumberFormatException数字格式化异常。 3、字符串(数组、java.util.List)越界错误 java.lang.StringIndexOutOfBoundsException java.lang.IndexOutOfBoundsException java.lang.ArrayIndexOutOfBoundsException 4、类定义未找到错误 java.lang.ClassNotFoundException 5、强制装换类型错误的时候 java.lang.ClassCastException 6、向方法传递了一个不合法或不正确的参数 java.lang.IllegalArgumentException 7、打开指定路径名表示的文件失败时 java.io.FileNotFoundException 8、指示主机 IP 地址无法确定而抛出的异常 java.net.UnknownHostException 四、portlet开发中需要注意的几个问题 1、JDK版本和Portal版本的兼容 2、使用第三方工具包的JDK以及Portal兼容 3、使用第三方工具包的操作平台兼容 相关资源:portal 开发指南
转载请注明原文地址: https://www.6miu.com/read-5049292.html

最新回复(0)