|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
什么时候上述的三种开发工具能和三为一,什么时候java的竞争力才更强,才有机会拉拢更多的程序员投入到对java的开发上,因为到时的开发工具将会比.net的更简单。还有一点也很关键,什么时候java推出的jsf能成为真正意义上的标准。
写三个java类,编译后放到Tomcat5.0webappstrutsWEB-INFclassescomjaver esttruts目次下
【HelloFrom.java】:
packagecom.javer.test.struts;
importjavax.servlet.http.HttpServletRequest;importorg.apache.struts.action.ActionError;importorg.apache.struts.action.ActionErrors;importorg.apache.struts.action.ActionForm;importorg.apache.struts.action.ActionMapping;
publicfinalclassHelloFromextendsActionForm{privateStringperson=null;publicStringgetPerson(){returnperson;}
publicvoidsetPerson(Stringperson){this.person=person;}
publicvoidreset(ActionMappingmapping,HttpServletRequestrequest){this.person=null;}
publicActionErrorsvalidate(ActionMappingmapping,HttpServletRequestrequest){ActionErrorserrors=newActionErrors();
if(this.person==null||this.person.length()<1)errors.add("person",newActionError("com.javer.test.struts.hello.error"));returnerrors;}}
【HelloModel.java】:
packagecom.javer.test.struts;
publicclassHelloModel{publicvoidsaveToPersistentStore(HelloFromhf){System.out.println("Hello"+hf.getPerson()+"!这里可存储数据到数据库中!");}}
【HelloAction.java】:
packagecom.javer.test.struts;
importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;
importorg.apache.struts.action.Action;importorg.apache.struts.action.ActionError;importorg.apache.struts.action.ActionErrors;importorg.apache.struts.action.ActionForm;importorg.apache.struts.action.ActionForward;importorg.apache.struts.action.ActionMapping;
importorg.apache.struts.util.MessageResources;
importorg.apache.commons.beanutils.PropertyUtils;
publicfinalclassHelloActionextendsAction{publicActionForwardexecute(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse)throwsException{MessageResourcesmessages=getResources(request);
ActionErrorserrors=newActionErrors();Stringperson=(String)PropertyUtils.getSimpleProperty(form,"person");
if(person.indexOf(",")!=-1){errors.add("person",newActionError("com.javer.test.struts.hello.unallowed.person",form));saveErrors(request,errors);request.removeAttribute(mapping.getAttribute());returnnewActionForward(mapping.getInput());}
HelloModelhm=newHelloModel();hm.saveToPersistentStore((HelloFrom)form);
request.removeAttribute(mapping.getAttribute());request.setAttribute("helloForm",form);
returnmapping.findForward("SayHello");}}
这个类不是struts必须的,是我为了转化编码而增添的
【EncodingFilter.java】:
packagecom.javer.test.struts;
importjava.io.IOException;importjavax.servlet.Filter;importjavax.servlet.FilterChain;importjavax.servlet.FilterConfig;importjavax.servlet.ServletException;importjavax.servlet.ServletRequest;importjavax.servlet.ServletResponse;
publicclassEncodingFilterimplementsFilter{protectedStringencoding=null;
protectedFilterConfigfilterConfig=null;
protectedbooleanignore=true;
publicvoiddestroy(){this.encoding=null;this.filterConfig=null;}
publicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,FilterChainchain)throwsIOException,ServletException{if(ignore||(request.getCharacterEncoding()==null)){request.setCharacterEncoding(selectEncoding(request));}chain.doFilter(request,response);}
publicvoidinit(FilterConfigfilterConfig)throwsServletException{
this.filterConfig=filterConfig;this.encoding=filterConfig.getInitParameter("encoding");Stringvalue=filterConfig.getInitParameter("ignore");if(value==null){this.ignore=true;}elseif(value.equalsIgnoreCase("true")||value.equalsIgnoreCase("yes")){this.ignore=true;}else{this.ignore=false;}}
protectedStringselectEncoding(ServletRequestrequest){return(this.encoding);}
publicFilterConfiggetFilterConfig(){returnfilterConfig;}
publicvoidsetFilterConfig(FilterConfigfilterConfig){this.filterConfig=filterConfig;}}
C#跟java类似,但是在跨平台方面理论上可以跨平台,实际上应用不大,执行性能优于java,跟C++基本一致,但是启动速度还是慢.代码安全,但容易性能陷阱. |
|