异常将上下文初始化事件发送到类的侦听器实例.[org.springframework.web.context.ContextLoaderListener]?

控制台:

五月 10, 2019 11:34:17 下午 org.apache.catalina.core.StandardContext listenerStart
严重: 异常将上下文初始化事件发送到类的侦听器实例.[org.springframework.web.context.ContextLoaderListener]
java.lang.IllegalStateException: The server encountered an internal error () that prevented it from fulfilling this request
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:288)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4682)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5150)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5">

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找 -->
    <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value>
    </context-param>

    <!-- 对Spring容器进行实例化 -->
    <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- springmvc前端控制器,rest配置 -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- contextConfigLocation配置springmvc加载的配置文件(配置处理器映射器、适配器等等) 如果不配置contextConfigLocation,默认加载的是/WEB-INF/servlet名称-serlvet.xml(springmvc-servlet.xml) -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/springmvc.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


    <filter>
        <filter-name>CharacterFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>CharacterFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
BeanCreationException: Error creating bean with name 'shiroFilter' defined in file
严重: 异常将上下文初始化事件发送到类的侦听器实例.[org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor': Cannot resolve reference to bean 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0' while setting bean property 'cacheOperationSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor#0' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'mvcRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mvcRealm': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadWarningDataRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:479) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:235) at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:703) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4699) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705) at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1720) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:479) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:428) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) at java.security.AccessController.doPrivileged(Native Method) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor': Cannot resolve reference to bean 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0' while setting bean property 'cacheOperationSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor#0' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'mvcRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mvcRealm': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadWarningDataRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102) at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:88) at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1037) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1011) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:473) ... 57 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor#0' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'mvcRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mvcRealm': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadWarningDataRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:479) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ... 74 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor#0' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'mvcRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mvcRealm': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadWarningDataRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102) at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:88) at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1037) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1011) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:473) ... 79 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in file [D:\work\kmddfxxt\out\artifacts\kmddfxxt\WEB-INF\classes\config\mfw-spring-components-shiro.xml]: Cannot resolve reference to bean 'mvcRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mvcRealm': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadWarningDataRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ... 96 more Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mvcRealm': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadWarningDataRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ... 106 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadWarningDataRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:240) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:923) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:804) at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:558) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:395) at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:220) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1267) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ... 116 more ![图片说明](https://img-ask.csdn.net/upload/201911/12/1573571608_902206.png)![图片说明](https://img-ask.csdn.net/upload/201911/12/1573571625_956803.png)![图片说明](https://img-ask.csdn.net/upload/201911/12/1573571633_738696.png)![图片说明](https://img-ask.csdn.net/upload/201911/12/1573571651_482264.png)![图片说明](https://img-ask.csdn.net/upload/201911/12/1573571697_252739.png)![图片说明](https://img-ask.csdn.net/upload/201911/12/1573571717_962603.png)
tomcat启动报错,有jar包
异常将上下文初始化事件发送到类的侦听器实例.[org.springframework.web.context.ContextLoaderListener] org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.alibaba.druid.pool.DruidDataSource] for bean with name 'dataSource' defined in file [D:\MyEclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\App-controller\WEB-INF\classes\spring\applicationContext-dao.xml]; nested exception is java.lang.ClassNotFoundException: com.alibaba.druid.pool.DruidDataSource at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1278) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1347) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:913) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:617) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4682) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5150) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.startup.Catalina.start(Catalina.java:633) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492) Caused by: java.lang.ClassNotFoundException: com.alibaba.druid.pool.DruidDataSource at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1363) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1186) at org.springframework.util.ClassUtils.forName(ClassUtils.java:265) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:419) at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1299) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1270) ... 39 more
C#通过Socket实现多文件传输
大概需求是客户端发送一个xml文件名给服务器,服务器返回xml文件。这一步没问题。 后面客户端需要解析xml文件,根据解析出的文件名,去服务器获取指定文件。现在问题是第一次服务器发送xml文件之后就侦听不到客户端后面的请求了 服务端代码: ``` #region 窗体加载 private void Form1_Load(object sender, EventArgs e) { Socket socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//Socket设置、IPv4、Stream类型套接字、TCP协议 IPAddress ip = IPAddress.Any;//获取本机IP IPEndPoint point = new IPEndPoint(ip, 18002);//设置IP和端口 socketWatch.Bind(point);//绑定端口 memoEdit1.Text = "开始侦听..."; socketWatch.Listen(100);//最大连接数 Thread th = new Thread(SendFileFuncssss);//创建新线程 th.Start(socketWatch);//启动线程 th.IsBackground = true;//设置后台运行线程 } #endregion #region 根据客户端传输文件名发送指定文件 public void SendFileFuncssss(object obj) { Socket socket = obj as Socket; while (true) { Socket socketServices = socket.Accept(); byte[] buffer = new byte[1024]; int num = socketServices.Receive(buffer);//接收到字节数 string str = Encoding.UTF8.GetString(buffer, 1, num - 1);//接收到字符串 if (buffer[0] == 0)//表示接收到的是消息数据 { TxtAddContent(socketServices.RemoteEndPoint + "连接成功"); string FileName = str; if (FileName.Equals("AutoUpdater.xml"))//获取xml配置文件 { //发送XML文件到客户端 using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + FileName, FileMode.Open)) { byte[] arrFile = new byte[1024 * 1024 * 5]; int length = fs.Read(arrFile, 0, arrFile.Length); byte[] arrFileSend = new byte[length + 1]; arrFileSend[0] = 1; // 用来表示发送的是xml文件数据 Buffer.BlockCopy(arrFile, 0, arrFileSend, 1, length); socketServices.Send(arrFileSend);// 发送数据到客户端 } } if (!FileName.Equals("AutoUpdater.xml")) { //发送更新文件到客户端 using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\FileFolder\\" + FileName, FileMode.Open)) { byte[] arrFile = new byte[1024 * 1024 * 50]; int length = fs.Read(arrFile, 0, arrFile.Length);//获取文件长度 byte[] arrFileSend = new byte[length + 1]; arrFileSend[0] = 1; // 用来表示发送的是xml文件数据 Buffer.BlockCopy(arrFile, 0, arrFileSend, 1, length); socketServices.Send(arrFileSend);// 发送数据到服务端 } } } } } #endregion ``` 客户端代码: ``` Socket socketClient = obj as Socket; socketClient.Connect(ipEndPoint); #region 修改本地文件名称 string Oldpath = AppDomain.CurrentDomain.BaseDirectory + "AutoUpdater.xml";//修改前名称 string Newpath = AppDomain.CurrentDomain.BaseDirectory + "AutoUpdater_Back.xml";//修改后名称 if (File.Exists(Oldpath)) { File.Delete(Newpath); File.Move(Oldpath, Newpath);//更改文件名 } #endregion if (socketClient.Connected) { try { TxtReceiveAddContent("连接成功"); //发送链接成功提示 byte[] arrMsg = Encoding.UTF8.GetBytes("AutoUpdater.xml"); byte[] arrSendMsg = new byte[arrMsg.Length + 1];//加一位标识用于表示是文字消息还是文件 arrSendMsg[0] = 0; // 用来表示发送的是消息数据 Buffer.BlockCopy(arrMsg, 0, arrSendMsg, 1, arrMsg.Length); socketClient.Send(arrSendMsg); //获取文件 string dirPath = Application.StartupPath; byte[] buffer = new byte[1024 * 1024 * 5]; int lenght = socketClient.Receive(buffer); if (buffer[0] == 1) { using (FileStream fs = new FileStream(dirPath + "\\AutoUpdater.xml", FileMode.Create)) { fs.Write(buffer, 1, lenght - 1); } TxtReceiveAddContent("配置文件接收成功:AutoUpdater.xml");//追加提示备注 } #region 获取XML里需要更新的文件和需要删除的文件 List<string> updatelist = new List<string>();//需要更新的文件集合 List<string> deletelist = new List<string>();//需要更新的文件集合 //获取历史xml文件更新时间以及更新版本 XDocument Olddocument = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "AutoUpdater_Back.xml"); //获取到XML的根元素进行操作 XElement Oldroot = Olddocument.Root; XElement Oldele = Oldroot.Element("UpdateInfo"); //获取旧更新时间标签的值 XElement OldUpdateTime = Oldele.Element("UpdateTime"); //获取旧版本号标签的值 XElement OldVersion = Oldele.Element("Version"); //获取最新xml文件更新时间以及更新版本 XDocument Newdocument = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "AutoUpdater.xml"); //获取到XML的根元素进行操作 XElement Newroot = Newdocument.Root; XElement Newele = Newroot.Element("UpdateInfo"); //获取旧更新时间标签的值 XElement NewUpdateTime = Newele.Element("UpdateTime"); //获取旧版本号标签的值 XElement NewVersion = Newele.Element("Version"); if (NewUpdateTime != OldUpdateTime || NewVersion != OldVersion) { //获取需要更新的文件列表 XElement NewUpList = Newroot.Element("UpdateList"); IEnumerable<XElement> UpList = NewUpList.Elements(); foreach (XElement item in UpList) { updatelist.Add(item.Value); } //获取需要删除的文件列表 XElement NewDelList = Newroot.Element("DeleteList"); IEnumerable<XElement> DelList = NewDelList.Elements(); foreach (XElement item in DelList) { deletelist.Add(item.Value); } } #endregion #region 循环获取更新文件 for (int i = 0; i < updatelist.Count; i++) { //发送链接成功提示 byte[] FileName = Encoding.UTF8.GetBytes(updatelist[i]); byte[] SendFileName = new byte[FileName.Length + 1];//加一位标识用于表示是文字消息还是文件 SendFileName[0] = 0; // 用来表示发送的是消息数据 Buffer.BlockCopy(FileName, 0, SendFileName, 1, FileName.Length); socketClient.Send(SendFileName); //获取文件 string FilePath = Application.StartupPath + "\\WebFile"; byte[] bufferByFile = new byte[1024 * 1024 * 50]; int lenghtByFile = socketClient.Receive(bufferByFile); if (bufferByFile[0] == 1) { using (FileStream fs = new FileStream(FilePath + "\\" + updatelist[i], FileMode.Create)) { fs.Write(bufferByFile, 1, lenghtByFile - 1); } TxtReceiveAddContent("文件接收成功:" + updatelist[i]); } } #endregion #region 循环删除指定文件 for (int i = 0; i < deletelist.Count; i++) { try { string path = AppDomain.CurrentDomain.BaseDirectory + "\\WebFile\\" + deletelist[i]; File.Delete(path); TxtReceiveAddContent("删除文件[" + deletelist[i] + "]成功"); } catch (Exception) { TxtReceiveAddContent("删除文件[" + deletelist[i] + "]失败"); continue; } } #endregion } catch (Exception ex) { File.Move(Newpath, Oldpath);//连接失败,还原文件名 MessageBox.Show(ex.ToString()); throw; } ``` 调试在客户端进循环的时候服务端侦听不到了 刚接触socket,多谢大佬们解答
安卓Android触摸事件侦听
1.安卓Android触摸事件侦听.mp4分别是 按下 按下移动 按下弹起 还有哪几种情况 除了可以监听framelayout 其他layout可以监听吗
安卓方面的问题,EditText的侦听事件
EditText侦听事件那几个方法我没有看懂,还有怎么能侦听我输入的值是多少
c#中的三个timer和thread引发异常时的处理
程序(exe)运行过程中,在没有catch的情况下,发生了异常 form的timer,弹出异常信息框; threading的timer和thread,直接导致整个程序停止运行,没有弹出异常信息框; System.Timers.Timer,则是什么事情也没发生。 请问导致这三种情况的原因在哪里,和调试器、未处理异常的侦听器有关么?
java简易计算器实现,添加能够切换简易计算器和科学计算器的按键。
![图片说明](https://img-ask.csdn.net/upload/201810/27/1540655964_202901.png) 现已有完整计算器框架和实现,但是需求有一条是: 能 通过菜单可以切换简易计算器和科学计算器。 如今就这个功能未实现,简易计算器就是只包含+、-、*、/的状态,而科学计算器则包括开方、平方、幂运算、1/n等操作。各运算已实现,但就是不知道怎么切换界面。求大神添加一个能够让其变化界面的按钮函数来实现。 附上代码: ``` import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; /** * 一个计算器,与Windows附件自带计算器的标准版功能、界面相仿。 但还不支持键盘操作。 */ public class Calculator extends JFrame implements ActionListener { /** 计算器上的键的显示名字 */ private final String[] KEYS = { "7", "8", "9", "÷", "sqrt", "4", "5", "6", "x", "%", "1", "2", "3", "-", "1/x", "0", "+/-", ".", "+", "=" }; /** 计算器上的功能键的显示名字 */ private final String[] COMMAND = { "Backspace", "CE", "C" }; /** 计算器左边的M的显示名字 */ private final String[] M = { " ", "MC", "MR", "MS", "M+" }; /** 计算器上键的按钮 */ private JButton keys[] = new JButton[KEYS.length]; /** 计算器上的功能键的按钮 */ private JButton commands[] = new JButton[COMMAND.length]; /** 计算器左边的M的按钮 */ private JButton m[] = new JButton[M.length]; /** 计算结果文本框 */ private JTextField resultText = new JTextField("0"); // 标志用户按的是否是整个表达式的第一个数字,或者是运算符后的第一个数字 private boolean firstDigit = true; // 计算的中间结果。 private double resultNum = 0.0; // 当前运算的运算符 private String operator = "="; // 操作是否合法 private boolean operateValidFlag = true; /** * 构造函数 */ public Calculator() { super(); // 初始化计算器 init(); // 设置计算器的背景颜色 this.setBackground(Color.BLACK); this.setTitle("计算器"); // 在屏幕(500, 300)坐标处显示计算器 this.setLocation(500, 300); // 不许修改计算器的大小 this.setResizable(false); // 使计算器中各组件大小合适 this.pack(); } /** * 初始化计算器 */ private void init() { // 文本框中的内容采用右对齐方式 resultText.setHorizontalAlignment(JTextField.RIGHT); // 不允许修改结果文本框 resultText.setEditable(false); // 设置文本框背景颜色为白色 resultText.setBackground(Color.WHITE); // 初始化计算器上键的按钮,将键放在一个画板内 JPanel calckeysPanel = new JPanel(); // 用网格布局器,4行,5列的网格,网格之间的水平方向间隔为3个象素,垂直方向间隔为3个象素 calckeysPanel.setLayout(new GridLayout(4, 5, 3, 3)); for (int i = 0; i < KEYS.length; i++) { keys[i] = new JButton(KEYS[i]); calckeysPanel.add(keys[i]); keys[i].setForeground(Color.blue); } // 运算符键用红色标示,其他键用蓝色表示 keys[3].setForeground(Color.red); keys[8].setForeground(Color.red); keys[13].setForeground(Color.red); keys[18].setForeground(Color.red); keys[19].setForeground(Color.red); // 初始化功能键,都用红色标示。将功能键放在一个画板内 JPanel commandsPanel = new JPanel(); // 用网格布局器,1行,3列的网格,网格之间的水平方向间隔为3个象素,垂直方向间隔为3个象素 commandsPanel.setLayout(new GridLayout(1, 3, 3, 3)); for (int i = 0; i < COMMAND.length; i++) { commands[i] = new JButton(COMMAND[i]); commandsPanel.add(commands[i]); commands[i].setForeground(Color.red); } // 初始化M键,用红色标示,将M键放在一个画板内 JPanel calmsPanel = new JPanel(); // 用网格布局管理器,5行,1列的网格,网格之间的水平方向间隔为3个象素,垂直方向间隔为3个象素 calmsPanel.setLayout(new GridLayout(5, 1, 3, 3)); for (int i = 0; i < M.length; i++) { m[i] = new JButton(M[i]); calmsPanel.add(m[i]); m[i].setForeground(Color.red); } // 下面进行计算器的整体布局,将calckeys和command画板放在计算器的中部, // 将文本框放在北部,将calms画板放在计算器的西部。 // 新建一个大的画板,将上面建立的command和calckeys画板放在该画板内 JPanel panel1 = new JPanel(); // 画板采用边界布局管理器,画板里组件之间的水平和垂直方向上间隔都为3象素 panel1.setLayout(new BorderLayout(3, 3)); panel1.add("North", commandsPanel); panel1.add("Center", calckeysPanel); // 建立一个画板放文本框 JPanel top = new JPanel(); top.setLayout(new BorderLayout()); top.add("Center", resultText); // 整体布局 getContentPane().setLayout(new BorderLayout(3, 5)); getContentPane().add("North", top); getContentPane().add("Center", panel1); getContentPane().add("West", calmsPanel); // 为各按钮添加事件侦听器 // 都使用同一个事件侦听器,即本对象。本类的声明中有implements ActionListener for (int i = 0; i < KEYS.length; i++) { keys[i].addActionListener(this); } for (int i = 0; i < COMMAND.length; i++) { commands[i].addActionListener(this); } for (int i = 0; i < M.length; i++) { m[i].addActionListener(this); } } /** * 处理事件 */ public void actionPerformed(ActionEvent e) { // 获取事件源的标签 String label = e.getActionCommand(); if (label.equals(COMMAND[0])) { // 用户按了"Backspace"键 handleBackspace(); } else if (label.equals(COMMAND[1])) { // 用户按了"CE"键 resultText.setText("0"); } else if (label.equals(COMMAND[2])) { // 用户按了"C"键 handleC(); } else if ("0123456789.".indexOf(label) >= 0) { // 用户按了数字键或者小数点键 handleNumber(label); // handlezero(zero); } else { // 用户按了运算符键 handleOperator(label); } } /** * 处理Backspace键被按下的事件 */ private void handleBackspace() { String text = resultText.getText(); int i = text.length(); if (i > 0) { // 退格,将文本最后一个字符去掉 text = text.substring(0, i - 1); if (text.length() == 0) { // 如果文本没有了内容,则初始化计算器的各种值 resultText.setText("0"); firstDigit = true; operator = "="; } else { // 显示新的文本 resultText.setText(text); } } } private void handleNumber(String key) { if (firstDigit) { // 输入的第一个数字 resultText.setText(key); } else if ((key.equals(".")) && (resultText.getText().indexOf(".") < 0)) { // 输入的是小数点,并且之前没有小数点,则将小数点附在结果文本框的后面 resultText.setText(resultText.getText() + "."); } else if (!key.equals(".")) { // 如果输入的不是小数点,则将数字附在结果文本框的后面 resultText.setText(resultText.getText() + key); } // 以后输入的肯定不是第一个数字了 firstDigit = false; } private void handleC() { // 初始化计算器的各种值 resultText.setText("0"); firstDigit = true; operator = "="; } private void handleOperator(String key) { if (operator.equals("÷")) { // 除法运算 // 如果当前结果文本框中的值等于0 if (getNumberFromText() == 0.0) { // 操作不合法 operateValidFlag = false; resultText.setText("除数不能为零"); } else { resultNum /= getNumberFromText(); } } else if (operator.equals("1/x")) { // 倒数运算 if (resultNum == 0.0) { // 操作不合法 operateValidFlag = false; resultText.setText("零没有倒数"); } else { resultNum = 1 / resultNum; } } else if (operator.equals("+")) { // 加法运算 resultNum += getNumberFromText(); } else if (operator.equals("-")) { // 减法运算 resultNum -= getNumberFromText(); } else if (operator.equals("x")) { // 乘法运算 resultNum *= getNumberFromText(); } else if (operator.equals("sqrt")) { // 平方根运算 resultNum = Math.sqrt(resultNum); } else if (operator.equals("%")) { // 百分号运算,除以100 resultNum = resultNum / 100; } else if (operator.equals("+/-")) { // 正数负数运算 resultNum = resultNum * (-1); } else if (operator.equals("=")) { // 赋值运算 resultNum = getNumberFromText(); } if (operateValidFlag) { // 双精度浮点数的运算 long t1; double t2; t1 = (long) resultNum; t2 = resultNum - t1; if (t2 == 0) { resultText.setText(String.valueOf(t1)); } else { resultText.setText(String.valueOf(resultNum)); } } // 运算符等于用户按的按钮 operator = key; firstDigit = true; operateValidFlag = true; } /** * 从结果文本框中获取数字 * * @return */ private double getNumberFromText() { double result = 0; try { result = Double.valueOf(resultText.getText()).doubleValue(); } catch (NumberFormatException e) { } return result; } public static void main(String args[]) { Calculator calculator1 = new Calculator(); calculator1.setVisible(true); calculator1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } ```
008的MSSQLSERVER 请求失败或服务未及时响应
以下是错误提示copy下来的一些信息: 服务器 TCP 提供程序无法在 [ 'any' <ipv6> 1433] 上侦听。TCP 端口已在使用中。 TDSSNIClient 初始化失败,出现错误 0x2740,状态代码 0xa。原因: 无法初始化 TCP/IP 侦听器。 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 TDSSNIClient 初始化失败,出现错误 0x2740,状态代码 0x1。原因: 初始化失败,出现基础结构错误。请检查以前的错误。 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 由于网络库中存在内部错误,所以无法启动网络库。要确定原因,请查看错误日志中紧位于此错误之前的那些错误。 SQL Server 无法生成 FRunCM 线程。请查看 SQL Server 错误日志和 Windows 事件日志,获取有关可能发生的相关问题的信息。 详情请打开http://bbs.csdn.net/topics/390314708 一样的情况求解决
能不能在jp3板块帮忙添加按钮插入图片功能和改变一下面板的背景颜色,拜托谢谢各位大神!
``` public class Client_Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String ipAdd = "127.0.0.1"; int port =8000; Client client = new Client(ipAdd,port); } } ``` ``` import java.awt.BorderLayout; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.net.Socket; import java.net.UnknownHostException; import javax.swing.*; public class Client extends JFrame { // 成员变量 JPanel jp1 = new JPanel(); JPanel jp2 = new JPanel(); JPanel jp3 = new JPanel(); JTextArea jta = new JTextArea(15, 40); JTextField jtf = new JTextField(); JButton jbt1 = new JButton("清除记录"); JButton jbt2 = new JButton("存储记录"); JButton jbt3 = new JButton("读取记录"); JLabel jlb = new JLabel(); FileWriter fw; FileReader fr; Socket socket = null; DataOutputStream dos = null; DataInputStream dis = null; String ipAdd = ""; int port = 0; String readStr = ""; String jtaStr = ""; // 构造方法 public Client(String ipAdd, int port) { setLocation(300, 400); setSize(400, 500); setVisible(true); add(jp1, BorderLayout.NORTH); add(jp2, BorderLayout.CENTER); add(jp3, BorderLayout.SOUTH); jp1.setLayout(new BorderLayout()); jp1.add(jta, BorderLayout.NORTH); jp1.add(jtf, BorderLayout.SOUTH); jp2.add(jbt1); jp2.add(jbt2); jp2.add(jbt3); jp3.add(jlb); jlb.setText("当前状态:"); pack(); this.ipAdd = ipAdd; this.port = port; // 调用网络连接 netConnect(); // 挂载侦听器 jtf.addActionListener(new MyActionListener()); jbt1.addActionListener(new MyActionListener()); jbt2.addActionListener(new MyActionListener()); jbt3.addActionListener(new MyActionListener()); } // 网络连接方法 public void netConnect() { try { socket = new Socket(this.ipAdd, this.port); jlb.setText("服务器连接成功" + socket); dos = new DataOutputStream(socket.getOutputStream()); dis = new DataInputStream(socket.getInputStream()); JtaReadThread jrt = new JtaReadThread(); Thread thread = new Thread(jrt); thread.start(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } // 新建侦听器类(内部类) private class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent arg0) { if (arg0.getSource().equals(jtf)) { try { dos.writeUTF(jtf.getText()); jtf.setText(""); // jta.setText(jta.getText()+"\n"+dis.readUTF()); } catch (IOException e) { e.printStackTrace(); } } if (arg0.getSource().equals(jbt1)) { jta.setText(""); } // 保存记录侦听器 if (arg0.getSource().equals(jbt2)) { byte b[] = jta.getText().getBytes(); try { fw = new FileWriter("d:\\chatLog2.txt", true); fw.write(jta.getText()); fw.close(); } catch (IOException e) { e.printStackTrace(); } jlb.setText("记录保存成功"); } // // 读取记录侦听器------jbt3 :FR读取记录 if (arg0.getSource().equals(jbt3)) { int b = 0; try { fr = new FileReader("d:\\chatLog2.txt"); while ((b = fr.read()) != -1) { System.out.print((char) b); } fr.close(); } catch (IOException e) { e.printStackTrace(); } } } } // 新建子线程类,用于读取服务器发送的广播数据 private class JtaReadThread implements Runnable { @Override public void run() { // TODO Auto-generated method stub while (true) { try { readStr = dis.readUTF(); jtaStr = jtaStr + '\n' + readStr; jta.setText(jtaStr ); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } ``` ``` import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.List; //服务器工作过程: //1.指定某个端口提供TCP服务 //2.等待客户端的连接(阻塞:傻等) //3.如果需要接收多个客户端,建议使用“死”循环语句 public class Server { ServerSocket ss = null; Socket socket = null; int port =0; //集合:用于存储每个客户端和服务器的连接(存储子线程) List<SubThread> mylist = new ArrayList<SubThread>(); Server(int port) { this.port = port; try { ss = new ServerSocket(this.port); System.out.println("服务器已经启动,port8000"); while (true) { socket = ss.accept(); System.out.println("客户端已连接"); //传递socket 给子线程,socket参数在构造方法中传递 SubThread subThread = new SubThread(socket); //将构造好的子线程实例存入集合中 mylist.add(subThread); Thread thread = new Thread(subThread); thread.start(); } } catch (IOException e) { e.printStackTrace(); } } //新建内部类:子线程 private class SubThread implements Runnable{ //成员变量:通道、读写 Socket socket = null; DataInputStream dis = null; DataOutputStream dos = null; String strRead = ""; SubThread(Socket socket){ this.socket = socket; try { dis = new DataInputStream(socket.getInputStream()); dos = new DataOutputStream(socket.getOutputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void run() { // TODO Auto-generated method stub //开始读写操作 while(true){ try { strRead = dis.readUTF(); System.out.println(strRead); for(int i=0; i<mylist.size(); i++){//遍历所有客户端,写! //取得当前的客户端的连接(socket)将strRead内容写给当前的客户端 mylist.get(i).dos.writeUTF(strRead); } } catch (IOException e) { e.printStackTrace(); } } } } } ``` ``` public class ServerRun { public static void main(String[] args) { // TODO Auto-generated method stub int serverPort = 8000; Server server = new Server(serverPort); } } ![图片说明](https://img-ask.csdn.net/upload/201906/27/1561601303_757012.jpg) ```
SQLSERVER Alwayson 在云服务器上,如何使用侦听的虚拟IP
对于云服务器是不是不能使用侦听的虚拟IP?我在主节点【servername:DB1】创建的侦听【ag_listener_1】只能在主服务器上访问,辅助节点【servername:DB2】用不了这个侦听,可以通过服务器名:DB1,windows身份访问。主、副节点的数据是同步的。
Java 自制的计算器菜单键无法复制
代码如下: import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JTextField; /** * 一个计算器,与Windows附件自带计算器的标准版功能、界面相仿。 但还不支持键盘操作。 */ public class Calculator extends JFrame implements ActionListener { /** 计算器上的键的显示名字 */ private final String[] KEYS = { "7", "8", "9", "/", "4", "5", "6", "*" , "1", "2", "3","-", "0","+/-",".","+", "1/x", "%", "sqrt", "=" }; /** 计算器上的功能键的显示名字 */ private final String[] COMMAND = { "Backspace", "C" }; /** 计算器上键的按钮 */ private JButton keys[] = new JButton[KEYS.length]; /** 计算器上的功能键的按钮 */ private JButton commands[] = new JButton[COMMAND.length]; /** 计算结果文本框 */ private JTextField resultText = new JTextField("0"); // private JMenuBar mb=new JMenuBar(); //编辑 private JMenu mEdit = new JMenu("编辑(E)"); //复制黏贴 private JMenuItem mCopy = new JMenuItem("复制(C)"); private JMenuItem mPaste = new JMenuItem("黏贴(V)"); //剪切板 private StringBuffer copyBoard=new StringBuffer(20); // 标志用户按的是否是整个表达式的第一个数字,或者是运算符后的第一个数字 private boolean firstDigit = true; // 计算的中间结果。 private double resultNum = 0.0; // 当前运算的运算符 private String operator = "="; // 操作是否合法 private boolean operateValidFlag = true; /** * 构造函数 */ public Calculator() { super(); // 初始化计算器 init(); // 设置计算器的背景颜色 this.setBackground(Color.LIGHT_GRAY); this.setTitle("计算器"); // 在屏幕(500, 300)坐标处显示计算器 this.setLocation(500, 300); // 许修改计算器的大小 this.setResizable(true); // 使计算器中各组件大小合适 this.pack(); //添加菜单与目录 this.setJMenuBar(mb); mb.add(mEdit); mEdit.setMnemonic(KeyEvent.VK_E); mEdit.add(mCopy); mEdit.add(mPaste); } /** * 初始化计算器 */ private void init() { // 文本框中的内容采用右对齐方式 resultText.setHorizontalAlignment(JTextField.RIGHT); // 允许修改结果文本框 resultText.setEditable(true); // 设置文本框背景颜色为白色 resultText.setBackground(Color.white); // 初始化计算器上键的按钮,将键放在一个画板内 JPanel calckeysPanel = new JPanel(); // 用网格布局器,5行,4列的网格,网格之间的水平方向间隔为3个象素,垂直方向间隔为3个象素 calckeysPanel.setLayout(new GridLayout(5, 4, 0, 0)); for (int i = 0; i < KEYS.length; i++) { keys[i] = new JButton(KEYS[i]); calckeysPanel.add(keys[i]); keys[i].setForeground(Color.black); } // 初始化功能键,都用红色标示。将功能键放在一个画板内 JPanel commandsPanel = new JPanel(); // 用网格布局器,1行,3列的网格,网格之间的水平方向间隔为3个象素,垂直方向间隔为3个象素 commandsPanel.setLayout(new GridLayout(1, 3, 0, 0)); for (int i = 0; i < COMMAND.length; i++) { commands[i] = new JButton(COMMAND[i]); commandsPanel.add(commands[i]); } // 下面进行计算器的整体布局,将calckeys和command画板放在计算器的中部, // 将文本框放在北部,将calms画板放在计算器的西部。 // 新建一个大的画板,将上面建立的command和calckeys画板放在该画板内 JPanel panel1 = new JPanel(); // 画板采用边界布局管理器,画板里组件之间的水平和垂直方向上间隔都为3象素 panel1.setLayout(new BorderLayout(3, 3)); panel1.add("North", commandsPanel); panel1.add("Center", calckeysPanel); // 建立一个画板放文本框 JPanel top = new JPanel(); top.setLayout(new BorderLayout()); top.add("Center", resultText); // 整体布局 getContentPane().setLayout(new BorderLayout(3, 5)); getContentPane().add("North", top); getContentPane().add("Center", panel1); // 为各按钮添加事件侦听器 // 都使用同一个事件侦听器,即本对象。本类的声明中有implements ActionListener for (int i = 0; i < KEYS.length; i++) { keys[i].addActionListener(this); } for (int i = 0; i < COMMAND.length; i++) { commands[i].addActionListener(this); } } /** * 处理事件 */ public void actionPerformed(ActionEvent e) { // 获取事件源的标签 String label = e.getActionCommand(); if(label.equals("复制(C)")) { String temp = resultText.getText().trim(); copyBoard.replace(0, copyBoard.length(), temp); } else if(label.equals("黏贴(V)")) { resultText.setText(copyBoard.toString()); }else if (label.equals(COMMAND[0])) { // 用户按了"Backspace"键 handleBackspace(); }else if (label.equals(COMMAND[1])) { // 用户按了"C"键 handleC(); } else if ("0123456789.".indexOf(label) >= 0) { // 用户按了数字键或者小数点键 handleNumber(label); // handlezero(zero); } else { // 用户按了运算符键 handleOperator(label); } } /** * 处理Backspace键被按下的事件 */ private void handleBackspace() { String text = resultText.getText(); int i = text.length(); if (i > 0) { // 退格,将文本最后一个字符去掉 text = text.substring(0, i - 1); if (text.length() == 0) { // 如果文本没有了内容,则初始化计算器的各种值 resultText.setText("0"); firstDigit = true; operator = "="; } else { // 显示新的文本 resultText.setText(text); } } } /** * 处理数字键被按下的事件 * * @param key */ private void handleNumber(String key) { if (firstDigit) { // 输入的第一个数字 resultText.setText(key); } else if ((key.equals(".")) && (resultText.getText().indexOf(".") < 0)) { // 输入的是小数点,并且之前没有小数点,则将小数点附在结果文本框的后面 resultText.setText(resultText.getText() + "."); } else if (!key.equals(".")) { // 如果输入的不是小数点,则将数字附在结果文本框的后面 resultText.setText(resultText.getText() + key); } // 以后输入的肯定不是第一个数字了 firstDigit = false; } /** * 处理C键被按下的事件 */ private void handleC() { // 初始化计算器的各种值 resultText.setText("0"); firstDigit = true; operator = "="; } /** * 处理运算符键被按下的事件 * * @param key */ private void handleOperator(String key) { if (operator.equals("/")) { // 除法运算 // 如果当前结果文本框中的值等于0 if (getNumberFromText() == 0.0) { // 操作不合法 operateValidFlag = false; resultText.setText("除数不能为零"); } else { resultNum /= getNumberFromText(); } } else if (operator.equals("1/x")) { // 倒数运算 if (resultNum == 0.0) { // 操作不合法 operateValidFlag = false; resultText.setText("零没有倒数"); } else { resultNum = 1 / resultNum; } } else if (operator.equals("+")) { // 加法运算 resultNum += getNumberFromText(); } else if (operator.equals("-")) { // 减法运算 resultNum -= getNumberFromText(); } else if (operator.equals("*")) { // 乘法运算 resultNum *= getNumberFromText(); } else if (operator.equals("sqrt")) { // 平方根运算 resultNum = Math.sqrt(resultNum); } else if (operator.equals("%")) { // 百分号运算,除以100 resultNum = resultNum / 100; } else if (operator.equals("+/-")) { // 正数负数运算 resultNum = resultNum * (-1); } else if (operator.equals("=")) { // 赋值运算 resultNum = getNumberFromText(); } if (operateValidFlag) { // 双精度浮点数的运算 long t1; double t2; t1 = (long) resultNum; t2 = resultNum - t1; if (t2 == 0) { resultText.setText(String.valueOf(t1)); } else { resultText.setText(String.valueOf(resultNum)); } } // 运算符等于用户按的按钮 operator = key; firstDigit = true; operateValidFlag = true; } /** * 从结果文本框中获取数字 * * @return */ private double getNumberFromText() { double result = 0; try { result = Double.valueOf(resultText.getText()).doubleValue(); } catch (NumberFormatException e) { } return result; } public static void main(String args[]) { Calculator calculator1 = new Calculator(); calculator1.setVisible(true); calculator1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
java键盘按键侦听事件响应
今天的第二个问题,代码如下 ``` addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { formKeyTyped(evt); } }); private void formKeyTyped(java.awt.event.KeyEvent evt) { // TODO add your handling code here: if(evt.getKeyCode()==KeyEvent.VK_0){ System.out.println("press 0"); } } ``` 我用的IDE是Netbeans,想写按键的响应,但是没有输出字符,不知道是什么原因? 大部分代码是自动生成的,我只写了formKeyTyped()方法里的响应代码?可是控制台依然没有输出,这是为什么啊?
关于侦听器和计时器实现定时采集信息的功能,定时器未能正常启动。
我写了一个servlet实现这个功能,但是在启动程序的时候好像定时器没启动帮我看下哪里错了。 ``` package sxdd.gps.maininfo; import javax.servlet.ServletContextEvent; public class MyTimer extends javax.servlet.http.HttpServlet implements javax.servlet.ServletContextListener { private java.util.Timer timer = null; public void contextInitialized(ServletContextEvent event) { timer = new java.util.Timer(true); event.getServletContext().log("定时器已启动"); System.out.println("定时器已启动"); timer.schedule(new MyTimerTask(),0,3*1000); event.getServletContext().log("已经添加任务调度表"); System.out.println("已经添加任务调度表"); } public void contextDestroyed(ServletContextEvent event) { timer.cancel(); event.getServletContext().log("定时器销毁"); System.out.println("定时器销毁"); } } package sxdd.gps.maininfo; import java.util.Calendar; import java.util.TimerTask; import javax.servlet.ServletContext; public class MyTimerTask extends TimerTask { private static boolean isRunning = false; private ServletContext context = null; public void StatisticsTask(ServletContext context) { this.context = context; } @Override public void run(){ if(!isRunning){ isRunning = true; //需要实现的功能的代码 System.out.println("++++++++++++++++++++++++++++++"); //任务结束 isRunning = false; }else{ context.log("上一次任务执行还未结束"); } } } <listener>      <listener-class>sxdd.gps.maininfo.MyTimer</listener-class>    </listener> ```
C# winform 没有终结点在侦听可以接受消息的。
没有终结点在侦听可以接受消息的。这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况,请参见 Inner,这个怎么解决?
eclipse运行tomcat出现http404
这是一个SSH项目struts2 Spring hibernate框架做成的项目 web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- spring监听器配置开始 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!--初始化Spring容器的侦听器 --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> </web-app> 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1202) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:428) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider] at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:128) at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:40) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257) ... 44 more Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider] at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:200) at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:125) ... 47 more Caused by: java.lang.ClassCastException: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider cannot be cast to org.hibernate.engine.jdbc.connections.spi.ConnectionProvider at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:197) ... 48 more
NS2.35 中实现MAC/802.11 的PCF接入方式
本人NS2萌新一枚写了一个DCF100节点有AP的仿真例子代码后面附上。 请问NS2.35上是否已经实现了802.11的PCF接入方式,若已经实现了请大佬们给个简单的例子。 若没有请大佬们告诉我该怎么做,已自闭。。。。。。。。。。。。 # DCF接入方式存在AP节点 set val(chan) Channel/WirelessChannel ;# 信道类型:无线 set val(prop) Propagation/TwoRayGround ;# 传输模型(两径模型:1.点到点间的直线。2.地面的反射) set val(netif) Phy/WirelessPhy ;# 物理接口类型:无线 set val(mac) Mac/802_11 ;# MAC层类型802.11 set val(ifq) Queue/DropTail/PriQueue ;# 网卡队列丢失类型:尾部丢弃(远距离衰落) set val(ll) LL ;# 逻辑链路层类型 set val(ant) Antenna/OmniAntenna ;# 天线类型:全向 set val(ifqlen) 50 ;# 网卡队列容量 set val(nn) 100 ;# 节点数量 set val(rp) AODV ;# 路由协议 set val(x) 500 set val(y) 500 # PCF设置参数: Mac/802_11 set Beacon 40 Mac/802_11 set CF-Poll 60 Mac/802_11 set CF-end 20 Mac/802_11 set CF-Null 34 #=========================545米通信范围其余均为默认======================================== # 通信(侦听)范围过大容易产生碰撞,使得丢包率大大增加,甚至无法传输到目的节点 #Phy/WirelessPhy set CPThresh_ 10.0 ;# 碰撞后功率强于另一个10倍的包被接收 Phy/WirelessPhy set CSThresh_ 1.55924e-11 ;# 550m侦听范围 Phy/WirelessPhy set RXThresh_ 1.61726e-11 ;# 545米通信范围值 #Phy/WirelessPhy set bandwidth_ 2e6 ;# 带宽2Mb #Phy/WirelessPhy set Pt_ 0.28183815 ;# 传输功率 #Phy/WirelessPhy set freq_ 914e+6 ;# 射频频率 #Phy/WirelessPhy set L_ 1.0 ;# 系统损耗系数 #================================end===================================================== #=============================NS2默认的802.11参数设定(802.11b)===================================== # 修改以下参数可以实现802.11a、802.11b、802.11g等MAC层协议 # DIFS = SIFS + (2 * Slot time) DCF采用DIFS # PIFS = SIFS + Slot time PCF的AP采用PIFS # DIFS > PIFS > SIFS,因此AP总比普通节点具有更高的访问信道的优先级(间隔越小优先级越高) # # 802.11 DCF使用CSMA/CA的方法来避免碰撞,在发送包之前,发送端会等待一个DIFS时间, # 如果在这段期间內侦测到其它在使用信道的话,发送端会把这次的发送任务延迟到信道空闲后再经过DIFS时间后再开始发送 # 此时,传送端会会使用随机数的方法选一个时间槽去重新发送这个包 # (随机数的范围由Contention Window,CW控制;初始只为CWmin,最大值为CWmax)。 # 随机退避时间:Backoff Time = Random()xSlotTime Random()取自[0,CW]中的一个随机数 # CW的初始值 = CWmin ,每次退避时CW=CWx2,当增大到CWmax时不再增大,发送成功后重置(reset) # 退避计数器值减至0时,一但信道空闲立即发送数据 # #Mac/802_11 set CWMin_ 31 ;# 退避随机数最小值 #Mac/802_11 set CWMax_ 1023 ;# 退避随机数最大值 #Mac/802_11 set SlotTime_ 0.000020 ;# SlotTime=20us #Mac/802_11 set SIFS_ 0.000010 ;# 最小帧间间隔 :10us; SIFS = 10us #Mac/802_11 set PreambleLength_ 144 ;# 144 bit #Mac/802_11 set PLCPHeaderLength_ 48 ;# 48 bits #Mac/802_11 set PLCPDataRate_ 1.0e6 ;# 1Mbps #Mac/802_11 set RTSThreshold_ 0 ;# 启用RTS/CTS机制的包大小0 bytes #Mac/802_11 set ShortRetryLimit_ 7 ;# 短帧最大重传尝试次数,包大小<RTS/CTS阈值 = 短帧 #Mac/802_11 set LongRetryLimit_ 4 ;# 长帧最大重传尝试次数,包大小>RTS/CTS阈值 = 长帧 #====================================end========================================================== # Mac/802_11 set dataRate_ 11Mb ;# 数据速率,DATA发送速率 # Mac/802_11 set basicRate_ 1Mb ;# 控制信息发送速率 # 创建仿真器和相应trace数据存储文件 set ns_ [new Simulator] set f [open PCF_100.tr w] $ns_ trace-all $f $ns_ eventtrace-all set nf [open PCF_100.nam w] $ns_ namtrace-all-wireless $nf val(x) val(y) ;# nam动画跟踪范围: 500 x 500 # 创建拓扑平面: val(x) x val(y) (500 x 500) set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # 创建val(nn) 100 个GOD数据结构,以记录路由信息 create-god $val(nn) set chan [new $val(chan)] ;# 创建无线信道 $ns_ node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channel $chan \ -topoInstance $topo \ -agentTrace ON \ -routerTrace OFF \ -macTrace ON \ -movementTrace OFF #===========================信标帧间隔和接入点模式说明========================================== # $mac_([expr $val(nn) - 1]) set BeaconInterval_ 0.2 ;#信标间隔时间 # Beacon Interval间隔调高,有助于发挥无线网络效能 ,client 端省电 # Beacon Interval间隔调低 ,可以加快wireless client 连结速度 . # # ACTIVE模式:这种模式下,STA在每个Channel(信道)上都会发出Probe Request帧用来搜索某个网络。 # PASSIVE模式:这种模式下,STA不发送任何信号,只是在ChannelList中各个信道间不断切换并等待Beacon帧。 #=====================================end====================================================== # “for” 循环创建 node 0~99 并设定节点坐标 10 x 10的矩阵拓扑 for {set i 0} {$i < 10} {incr i} { for {set j 0} {$j < 10} {incr j} { set k [expr $i*10+$j] set node_($k) [$ns_ node] $node_($k) random-motion 0 ;#不移动 $node_($k) set X_ [expr $j*50] $node_($k) set Y_ [expr $i*50] $node_($k) set Z_ 0.0 set mac_($k) [$node_($k) getMac 0] if {$k != 44} { ;# 其余节点为ACTIVE模式下的STA $ns_ at 0.1 "$mac_($k) ScanType ACTIVE" } else { ;# 设置node44为AP(PC) set AP_ADDR1 [$mac_($k) id] $mac_($k) ap $AP_ADDR1 $ns_ at 0.01 "$node_($k) color \"red\"" } } } $mac_(44) set BeaconInterval_ 0.5 # 建立node0与done99的tcp连接(node0发,node99收),传输数据类型CBR set tcp [new Agent/TCP] $ns_ attach-agent $node_(0) $tcp set null [new Agent/TCPSink] $ns_ attach-agent $node_(99) $null $ns_ connect $tcp $null set cbr [new Application/Traffic/CBR] $cbr attach-agent $tcp # node0的恒定速率源的设定 $cbr set type_ CBR ;# 数据源类型恒定速率 $cbr set packet_size_ 1000 ;# 包大小 1000Byte $cbr set rate_ 1Mb ;# 速率: 1 Mbit/s $cbr set random_ false ;# 速率不变 $ns_ at 0.5 "$cbr start" ;# 0.5秒时产生数据 $ns_ at 26.0 "$cbr stop" ;# 26秒时结束数据的产生 # 结束时 “for” 循环重置node0~99 for {set i 0} {$i < 100} {incr i} { $ns_ initial_node_pos $node_($i) 30 $ns_ at 28.0 "$node_($i) reset" ;# 28sec时将节点设置恢复为默认 } # 30sec 调用finish函数,20.1 结束仿真 $ns_ at 30.0 "finish" $ns_ at 30.1 "puts \"NS EXITING...\"; $ns_ halt" # finish函数,关闭trace文件并调用nam动画演示仿真 proc finish {} { global ns_ f nf val $ns_ flush-trace close $f close $nf exec nam PCF_100.nam & exit 0 } $ns_ run ;#执行仿真
eXosip创建会话过程中接受到的事件的tid问题
刚开始学习eXosip,编译了网上一个大牛的代码,发现了一个问题。当UAC发送INVITE后,UAS收到后回发一个Ringing,他们的tid都为一,但是如果我把UAS关闭后再打开,UAC发送INVITE,UAS的tid为1,但是UAC收到的tid是2,这是为什么呢? UAS代码: # include <eXosip2/eXosip.h> # include <stdio.h> # include <stdlib.h> # include <Winsock2.h> int main (int argc, char *argv[]) { eXosip_event_t *je = NULL; osip_message_t *ack = NULL; osip_message_t *invite = NULL; osip_message_t *answer = NULL; sdp_message_t *remote_sdp = NULL; int call_id, dialog_id; int i,j; int id; char *sour_call = "sip:140@127.0.0.1"; char *dest_call = "sip:133@127.0.0.1:15060";//client ip char command; char tmp[4096]; int pos = 0; //初始化sip i = eXosip_init (); if (i != 0) { printf ("Can't initialize eXosip!\n"); return -1; } else { printf ("eXosip_init successfully!\n"); } i = eXosip_listen_addr (IPPROTO_UDP, NULL, 15061, AF_INET, 0); if (i != 0) { eXosip_quit (); fprintf (stderr, "eXosip_listen_addr error!\nCouldn't initialize transport layer!\n"); } for(;;) { //侦听是否有消息到来 je = eXosip_event_wait (0,50); //协议栈带有此语句,具体作用未知 eXosip_lock (); eXosip_default_action (je); //printf("call_id is %d,dialog_id is %d \n", je->cid, je->did); eXosip_automatic_refresh (); eXosip_unlock (); if (je == NULL)//没有接收到消息 continue; // printf ("the cid is %s, did is %s/n", je->did, je->cid); switch (je->type) { case EXOSIP_MESSAGE_NEW://新的消息到来 printf (" EXOSIP_MESSAGE_NEW!\n"); if (MSG_IS_MESSAGE (je->request))//如果接受到的消息类型是MESSAGE { { osip_body_t *body; osip_message_get_body (je->request, 0, &body); printf ("I get the msg is: %s\n", body->body); printf ("the cid is %s, did is %s/n", je->did, je->cid); } //按照规则,需要回复OK信息 eXosip_message_build_answer (je->tid, 200,&answer); eXosip_message_send_answer (je->tid, 200,answer); } break; case EXOSIP_CALL_INVITE: //得到接收到消息的具体信息 printf ("Received a INVITE msg from %s:%s, UserName is %s, password is %s\n",je->request->req_uri->host, je->request->req_uri->port, je->request->req_uri->username, je->request->req_uri->password); //得到消息体,认为该消息就是SDP格式. remote_sdp = eXosip_get_remote_sdp (je->did); call_id = je->cid; dialog_id = je->did; printf("call_id is %d,dialog_id is %d \n", je->cid, je->did); eXosip_lock (); eXosip_call_send_answer (je->tid, 180, NULL); printf("je->tid is %d \n",je->tid); i = eXosip_call_build_answer (je->tid, 200, &answer); printf("je->tid is %d \n", je->tid); if (i != 0) { printf ("This request msg is invalid!Cann't response!\n"); eXosip_call_send_answer (je->tid, 400, NULL); } else { _snprintf_s (tmp, 4096, "v=0\r\n" "o=anonymous 0 0 IN IP4 0.0.0.0\r\n" "t=1 10\r\n" "a=username:rainfish\r\n" "a=password:123\r\n"); //设置回复的SDP消息体,下一步计划分析消息体 //没有分析消息体,直接回复原来的消息,这一块做的不好。 osip_message_set_body (answer, tmp, strlen(tmp)); osip_message_set_content_type (answer, "application/sdp"); eXosip_call_send_answer (je->tid, 200, answer); printf ("send 200 over!\n"); } eXosip_unlock (); //显示出在sdp消息体中的attribute 的内容,里面计划存放我们的信息 printf ("the INFO is :\n"); while (!osip_list_eol ( &(remote_sdp->a_attributes), pos)) { sdp_attribute_t *at; at = (sdp_attribute_t *) osip_list_get ( &remote_sdp->a_attributes, pos); printf ("%s : %s\n", at->a_att_field, at->a_att_value);//这里解释了为什么在SDP消息体中属性a里面存放必须是两列 pos ++; } break; case EXOSIP_CALL_ACK: printf ("ACK recieved!\n"); //printf ("the cid is %s, did is %s/n", je->did, je->cid); break; case EXOSIP_CALL_CLOSED: printf ("the remote hold the session!\n"); // eXosip_call_build_ack(dialog_id, &ack); //eXosip_call_send_ack(dialog_id, ack); i = eXosip_call_build_answer (je->tid, 200, &answer); if (i != 0) { printf ("This request msg is invalid!Cann't response!\n"); eXosip_call_send_answer (je->tid, 400, NULL); } else { eXosip_call_send_answer (je->tid, 200, answer); printf ("bye send 200 over!\n"); } break; case EXOSIP_CALL_MESSAGE_NEW://至于该类型和EXOSIP_MESSAGE_NEW的区别,源代码这么解释的 /* // request related events within calls (except INVITE) EXOSIP_CALL_MESSAGE_NEW, < announce new incoming request. // response received for request outside calls EXOSIP_MESSAGE_NEW, < announce new incoming request. 我也不是很明白,理解是:EXOSIP_CALL_MESSAGE_NEW是一个呼叫中的新的消息到来,比如ring trying都算,所以在接受到后必须判断 该消息类型,EXOSIP_MESSAGE_NEW而是表示不是呼叫内的消息到来。 该解释有不妥地方,仅供参考。 */ printf(" EXOSIP_CALL_MESSAGE_NEW\n"); if (MSG_IS_INFO(je->request) ) //如果传输的是INFO方法 { eXosip_lock (); i = eXosip_call_build_answer (je->tid, 200, &answer); if (i == 0) { eXosip_call_send_answer (je->tid, 200, answer); } eXosip_unlock (); { osip_body_t *body; osip_message_get_body (je->request, 0, &body); printf ("the body is %s\n", body->body); } } break; default: printf ("Could not parse the msg!\n"); } } } UAC的代码: #include <eXosip2/eXosip.h> #include <stdio.h> #include <stdlib.h> #include <winsock2.h> int main(int argc, char *argv[]) { struct eXosip_t *context_eXosip; eXosip_event_t *je; osip_message_t *reg = NULL; osip_message_t *invite = NULL; osip_message_t *ack = NULL; osip_message_t *info = NULL; osip_message_t *message = NULL; int call_id, dialog_id; int i, flag; int flag1 = 1; char *source_call = "sip:140@127.0.0.1";//UAC1,端口是15060 char *dest_call = "sip:133@127.0.0.1:15061";//UAS,端口是15061 //在这个例子中,uac和uas通信,则source就是自己的地址,而目的地址就是uac1的地址 char command; char tmp[4096]; printf("i 发起呼叫请求\n\n"); printf("h 挂断\n\n"); printf("q 退出程序\n\n"); printf("s 执行方法INFO\n\n"); printf("m 执行方法MESSAGE\n\n"); //初始化 i = eXosip_init(); if (i != 0) { printf("Couldn't initialize eXosip!\n"); return -1; } else { printf("eXosip_init successfully!\n"); } //绑定uac自己的端口15060,并进行端口监听 i = eXosip_listen_addr(IPPROTO_UDP, NULL, 15060, AF_INET, 0); if (i != 0) { eXosip_quit(); fprintf(stderr, "Couldn't initialize transport layer!\n"); return -1; } flag = 1; while (flag) { //输入命令 printf("Please input the command:\n"); scanf_s("%c", &command,1); getchar(); switch (command) { case 'i'://INVITE,发起呼叫请求 i = eXosip_call_build_initial_invite(&invite, dest_call, source_call, NULL, "This is a call for conversation"); if (i != 0) { printf("Initial INVITE failed!\n"); break; } //格式vot必不可少,原因未知,估计是协议栈在传输时需要检查的 _snprintf_s(tmp, 4096, "v=0\r\n" "o=anonymous 0 0 IN IP4 0.0.0.0\r\n" "t=1 10\r\n" "a=username:htc\r\n" "a=password:070011\r\n"); osip_message_set_body(invite, tmp, strlen(tmp)); osip_message_set_content_type(invite, "application/sdp"); eXosip_lock(); i = eXosip_call_send_initial_invite(invite); //invite SIP INVITE message to send eXosip_unlock(); //发送了INVITE消息,等待应答 flag1 = 1; while (flag1) { je = eXosip_event_wait(0, 200); //Wait for an eXosip event //(超时时间秒,超时时间毫秒) printf("je->tid is %d \n", je->tid); if (je == NULL) { printf("No response or the time is over!\n"); break; } switch (je->type) //可能会到来的事件类型 { case EXOSIP_CALL_PROCEEDING: //收到100 trying消息,表示请求正在处理中 printf("proceeding!\n"); break; case EXOSIP_CALL_RINGING: //收到180 Ringing应答,表示接收到INVITE请求的UAS正在向被叫用户振铃 printf("ringing!\n"); printf("je->tid is %d \n", je->tid); printf("call_id is %d,dialog_id is %d \n", je->cid, je->did); break; case EXOSIP_CALL_ANSWERED: //收到200 OK,表示请求已经被成功接受,用户应答 printf("ok!connected!\n"); call_id = je->cid; dialog_id = je->did; printf("call_id is %d,dialog_id is %d \n", je->cid, je->did); //回送ack应答消息 eXosip_call_build_ack(je->did, &ack); eXosip_call_send_ack(je->did, ack); flag1 = 0; //推出While循环 break; case EXOSIP_CALL_CLOSED: //a BYE was received for this call printf("the other sid closed!\n"); break; case EXOSIP_CALL_ACK: //ACK received for 200ok to INVITE printf("ACK received!\n"); break; default: //收到其他应答 printf("other response!\n"); break; } eXosip_event_free(je); //Free ressource in an eXosip event } break; case 'h': //挂断 printf("Holded!\n"); eXosip_lock(); eXosip_call_terminate(call_id, dialog_id); eXosip_unlock(); break; case 's': //传输INFO方法 eXosip_call_build_info(dialog_id, &info); _snprintf_s(tmp, 4096, "\nThis is a sip message(Method:INFO)"); osip_message_set_body(info, tmp, strlen(tmp)); //格式可以任意设定,text/plain代表文本信息; osip_message_set_content_type(info, "text/plain"); eXosip_call_send_request(dialog_id, info); break; case 'm': //传输MESSAGE方法,也就是即时消息,和INFO方法相比,我认为主要区别是: //MESSAGE不用建立连接,直接传输信息,而INFO消息必须在建立INVITE的基础上传输 printf("the method : MESSAGE\n"); eXosip_message_build_request(&message, "MESSAGE", dest_call, source_call, NULL); //内容,方法, to ,from ,route _snprintf_s(tmp, 4096, "This is a sip message(Method:MESSAGE)"); osip_message_set_body(message, tmp, strlen(tmp)); //假设格式是xml osip_message_set_content_type(message, "text/xml"); eXosip_message_send_request(message); break; case 'q': eXosip_quit(); printf("Exit the setup!\n"); flag = 0; break; } } return(0); }
当程序意外中止后,点击事件怎么就无效了呢?附上侦听事件代码
![![![![图片说明](https://img-ask.csdn.net/upload/201506/05/1433491491_264864.png)图片说明](https://img-ask.csdn.net/upload/201506/05/1433491481_871910.png)图片说明](https://img-ask.csdn.net/upload/201506/05/1433491524_240747.png)图片说明](https://img-ask.csdn.net/upload/201506/05/1433491516_659987.png)
JAVA通讯录 TXT文档分页问题
我在做一个JAVA通讯录,想请问一下如何把这个TXT文档 超过20行分页显示,请前辈们多多指教,谢谢 方便的话请帮我写一下代码看看行吗 package MyAddBook; import java.awt.Choice;//选择 import java.awt.Container;//容器 import java.awt.Frame; import java.awt.GridLayout;//间距 import java.awt.Toolkit;//居中 import java.awt.event.ActionEvent;//事件 import java.awt.event.ActionListener;//监听 import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter;//文本输出流打印对象的格式化 import java.text.Collator;//区分语言 import java.util.Arrays; import java.util.Comparator;//排序 import java.util.Scanner; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenuBar; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane;//消息提示框 import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class MyAddBook { public static JFrame frame; public MyAddBook() { frame=new JFrame("通讯录");//面板标题 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//单击关闭按钮关闭窗口 frame.setVisible(true);//窗口可见 /* * 在一个窗口中,我们经常需要给窗口添加菜单条。在 Java * 中这一部分是由三个类实现的,它们是JMenuBar、JMenu和JMenuItem, 分别对应菜单条、菜单和菜单项。 * 同时,可以给JMenuItem注册侦听器,但不能对JMenuBar,JMenu注册侦听器. * * 一、菜单条(JMenuBar) * JMenuBar 的构造方法是 JMenuBar(),相当简单。在构造之后,还要将它设置成窗口的菜单条,这里要用 setJMenuBar * 方法: JMenuBar TestJMenuBar=new JMenuBar(); * TestFrame.setJMenuBar(TestJMenuBar); 需要说明的是,JMenuBar 类根据 JMenu * 添加的顺序从左到右显示,并建立整数索引。 * * 二、菜单(JMenu) 在添加完菜单条后,并不会显示任何菜单,所以还需要在菜单条中添加菜单。菜单 * JMenu 类的构造方法有4种: JMenu() 构造一个空菜单。 JMenu(Action a) * 构造一个菜单,菜单属性由相应的动作来提供。 JMenu(String s) 用给定的标志构造一个菜单。 JMenu(String * s,Boolean b) 用给定的标志构造一个菜单。如果布尔值为false,那么当释放鼠标按钮后,菜单项会消失;如果布尔值为true, * 那么当释放鼠标按钮后,菜单项仍将显示。这时的菜单称为 tearOff 菜单。 在构造完后,使用 JMenuBar 类的 add * 方法添加到菜单条中。 * * 三、菜单项(JmenuItem) 接下来的工作是往菜单中添加内容。 * 在菜单中可以添加不同的内容,可以是菜单项(JMenuItem),可以是一个子菜单,也可以是分隔符。 在构造完后,使用 JMenu 类的 * add 方法添加到菜单中。 子菜单的添加是直接将一个子菜单添加到母菜单中,而分隔符的添加只需要将分隔符作为菜单项添加到菜单中。 */ JMenuBar bar=new JMenuBar(); JMenu edit=new JMenu("编辑"); JMenuItem edit1=new JMenuItem("录入"); JMenuItem edit2=new JMenuItem("查询"); JMenuItem edit3=new JMenuItem("删除"); JMenuItem edit4=new JMenuItem("修改"); JMenuItem edit5=new JMenuItem("排序"); edit1.addActionListener(new Type());//监听 JMenu show=new JMenu("按性别显示"); JMenuItem show1=new JMenuItem("男"); JMenuItem show2=new JMenuItem("女"); Container c=frame.getContentPane(); JPanel p=new JPanel(); c.add(p); p.add(bar); bar.add(edit); bar.add(show); edit.add(edit1); edit.add(edit2); edit.add(edit3); edit.add(edit4); edit.add(edit5); show.add(show1); show.add(show2); // 获取你的屏幕的宽和高 int width = Toolkit.getDefaultToolkit().getScreenSize().width; int height = Toolkit.getDefaultToolkit().getScreenSize().height; // 然后设置你编写的窗口的初始位置,也就是在中间, frame.setLocation(width / 2 - 200, height / 2 - 150); frame.setSize(500, 300); /* * 1. JFrame是javax.swing.JFrame的类,Frame是Java.awt.Frame的类 * * 2. 关闭窗口的方式不同: * 2.1 JFrame的关闭方式:传递参数使得关闭按钮有效 * Frame的关闭方式:加监听使得关闭按钮有效 */ edit2.addActionListener(new ActionListener() // 监听查询 { public void actionPerformed(ActionEvent e) { new Operation("查询", 2).dialog.setVisible(true); } }); edit3.addActionListener(new ActionListener() // 监听删除 { public void actionPerformed(ActionEvent e) { //获取你的屏幕的宽和高 int width = Toolkit.getDefaultToolkit().getScreenSize().width; int height = Toolkit.getDefaultToolkit().getScreenSize().height; //然后设置你编写的窗口的初始位置,也就是在中间, frame.setLocation(width / 2 - 200, height / 2 - 150); new Operation("删除", 3).dialog.setVisible(true); } }); edit4.addActionListener(new ActionListener() // 监听修改 { public void actionPerformed(ActionEvent e) { new Operation("修改", 4).dialog.setVisible(true); } }); // 输出类 edit5.addActionListener(new ActionListener() // 监听排序 { public void actionPerformed(ActionEvent e) { new Print("按姓名排序后", 2);//调用 排序 函数 } }); show1.addActionListener(new ActionListener() // 监听男 { public void actionPerformed(ActionEvent e) { new Print("男", 1);//调用 匹配 显示 } }); show2.addActionListener(new ActionListener() // 监听女 { public void actionPerformed(ActionEvent e) { new Print("女", 1);//调用 匹配 显示 } }); } public static void main(String[] args) { new MyAddBook(); } public String[] getSortOfChinese(String[] a) { // Collator 类是用来执行区分语言环境,这里使用CHINA Comparator cmp = Collator.getInstance(java.util.Locale.CHINA); // JDKz自带对数组进行排序。 Arrays.sort(a, cmp); return a; } } class Operation{ private Frame frame; /* * public JDialog(Dialog owner, String title, boolean modal) * 创建一个具有指定标题、模式和指定所有者 Dialog 的对话框。 此构造方法将该组件的语言环境属性设置为 * JComponent.getDefaultLocale 所返回的值。 * * 参数: owner - 显示该对话框的所有者 Dialog; 如果此对话框没有所有者,则为 null * title -该对话框的标题栏中所显示的 String * modal - 指定对话框在显示时是否阻塞用户向其他顶层窗口输入。如果为true,则模式类型属性被设置为 DEFAULT_MODALITY_TYPE; * 否则对话框是无模式的。 * 抛出: * HeadlessException - 如果 GraphicsEnvironment.isHeadless() 返回 true。 */ JDialog dialog = new JDialog(frame, "查询对话框", true); public Operation(String str, int n) { dialog.setSize(450, 300); //获取你的屏幕的宽和高 int width = Toolkit.getDefaultToolkit().getScreenSize().width; int height = Toolkit.getDefaultToolkit().getScreenSize().height; //然后设置你编写的窗口的初始位置,也就是在中间, dialog.setLocation(width / 2 - 200, height / 2 - 150); Container c = dialog.getContentPane(); /*GridLayout(int rows, int cols, int hgap, int vgap) : 创建具有指定行数、列数以及组件水平、纵向一定间距的网格布局。*/ dialog.setLayout(new GridLayout(2, 1, 5, 5)); JLabel LOperation = new JLabel("请输入要" + str + "人员的名字"); final JTextField Tname = new JTextField(10);//单行文本输入框 JButton sure = new JButton("确定"); JButton cancel = new JButton("取消"); JPanel pane1 = new JPanel(); JPanel pane2 = new JPanel(); c.add(pane1); c.add(pane2); pane1.add(LOperation); pane1.add(Tname); pane2.add(sure); pane2.add(cancel); dialog.setDefaultCloseOperation(dialog.DISPOSE_ON_CLOSE); if (n == 2) { sure.addActionListener(new ActionListener() // 查询 { public void actionPerformed(ActionEvent e) { try { FileReader file = new FileReader("D:\\AddressBook.txt"); Scanner find = new Scanner(file); /* * 这里while括号里面的find.hasNext()方法用于判断find对象中有没有下一条数据 * 返回 bool 值 , 有则返回true 无 则返回false * 下面的find.next()是获取find对象中的值 然后赋值给 str 然后输出这个方法 * 其实就是循环输出it 对象中所有的值 */ while (find.hasNext()) { if (find.next().equals(Tname.getText())) { dialog.dispose();//关闭窗体,并释放一部分资源。 Type fd = new Type(); fd.frame = new JFrame("查询结果如下"); fd.Tname.setText(Tname.getText()); fd.Csex.select(find.next()); fd.Tunit.setText(find.next()); fd.Thomephone.setText(find.next()); fd.Temail.setText(find.next()); fd.Ttelephone.setText(find.next()); fd.Type(); } } file.close(); find.close(); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block // e1.printStackTrace(); System.out.print("未找到文件"); } catch (IOException e2) { // TODO Auto-generated catch block // e2.printStackTrace(); System.out.print("未找到该人员"); } } }); } if (n == 3) { sure.addActionListener(new ActionListener() // 删除 { public void actionPerformed(ActionEvent e) { try { File file = new File("D:\\AddressBook.txt");//创建文件 Scanner find = new Scanner(file);//输入 FileWriter file1 = new FileWriter("D:\\AddressBook1.txt", true); PrintWriter write = new PrintWriter(file1); while (find.hasNext()) {//取下一个元素 String s = find.next(); if (!(s.equals(Tname.getText()))) { write.print(s + "\t"); write.print(find.next() + "\t"); write.print(find.next() + "\t\t"); write.print(find.next() + "\t\t"); write.print(find.next() + "\t\t"); write.println(find.next()); } else { find.next(); find.next(); find.next(); find.next(); find.next(); } } // file.close(); find.close(); file.delete(); write.close(); file1.close(); File file2 = new File("D:\\AddressBook1.txt"); file2.renameTo(new File("D:\\AddressBook.txt")); JOptionPane.showMessageDialog(null, "删除成功", "删 除 结 果", JOptionPane.INFORMATION_MESSAGE); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block // e1.printStackTrace(); JOptionPane.showMessageDialog(null, "未找到文件"); } catch (IOException e2) { // TODO Auto-generated catch block // e2.printStackTrace(); System.out.print("未找到该人员"); } } }); } if (n == 4) { sure.addActionListener(new ActionListener() // 修改 { public void actionPerformed(ActionEvent e) { try { File file = new File("D:\\AddressBook.txt"); Scanner find = new Scanner(file); FileWriter file1 = new FileWriter("D:\\AddressBook1.txt", true); PrintWriter write = new PrintWriter(file1); while (find.hasNext()) { String s = find.next(); if (!(s.equals(Tname.getText()))) { write.print(s + "\t"); write.print(find.next() + "\t"); write.print(find.next() + "\t\t"); write.print(find.next() + "\t\t"); write.print(find.next() + "\t\t"); write.println(find.next()); } else { dialog.dispose(); Type fd = new Type(); Type.y = 1; fd.frame = new JFrame("查询结果如下"); fd.Tname.setText(Tname.getText()); String s1 = find.next(); fd.Csex.select(s1); String s2 = find.next(); fd.Tunit.setText(s2); String s5 = find.next(); fd.Thomephone.setText(s5); String s6 = find.next(); fd.Temail.setText(s6); String s7 = find.next(); fd.Ttelephone.setText(s7); fd.Type(); if (Type.z == 1) { write.print(Tname.getText() + "\t"); write.print(s1 + "\t"); write.print(s2 + "\t\t"); write.print(s5 + "\t\t"); write.print(s6 + "\t\t"); write.println(s7); Type.z = 2; } } } // file.close(); find.close(); file.delete(); write.close(); file1.close(); File file2 = new File("D:\\AddressBook1.txt"); file2.renameTo(new File("D:\\AddressBook.txt")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block // e1.printStackTrace(); System.out.print("未找到文件"); } catch (IOException e2) { // TODO Auto-generated catch block // e2.printStackTrace(); System.out.print("未找到该人员"); } } }); } cancel.addActionListener(new ActionListener() // 取消 { public void actionPerformed(ActionEvent e) { dialog.dispose();//关闭查询面板 } }); } } class Print{ public JTextArea area;// 多行文本输入框 public Print(String st, int n) { JFrame frame = new JFrame(st + "信息如下"); area = new JTextArea();// 多行文本输入框 frame.add(area); frame.setVisible(true); frame.setSize(1000, 500); frame.setLocation(350, 150);// 显示位置坐标 if (n == 2) try // 排序 { int i, j, k; String[] all; all = new String[1000]; BufferedReader read = new BufferedReader(new FileReader("D:\\AddressBook.txt")); area.append("姓 名" + "\t" + "性别" + "\t" + "单位" + "\t\t" + "住宅电话" + "\t\t" + "Email" + "\t\t\t" + "移动电话" + '\n'); int z = 1, count = 0; while (z == 1) { for (i = 0; i < 1000; i++) { String str = read.readLine(); if (str != null) { all[i] = str; count++; } else z = 0; } } String[] bll; bll = new String[count]; for (i = 0; i < count; i++) bll[i] = all[i]; getSortOfChinese(bll);// 调用排序函数 for (i = 0; i < count; i++) area.append(bll[i] + '\n');// 在指定元素的结尾追加内容 read.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e2) { e2.printStackTrace(); } if (n == 1) try // 指定类人员 { FileReader file = new FileReader("D:\\AddressBook.txt"); Scanner find = new Scanner(file); area.append("姓 名" + "\t" + "性别" + "\t" + "单位" + "\t\t" + "住宅电话" + "\t\t" + "Email" + "\t\t\t" + "移动电话" + '\n'); while (find.hasNext()) { String str1 = find.next(); String str2 = find.next(); if (str2.equals(st)) { area.append(str1 + "\t"); area.append(str2 + "\t"); area.append(find.next() + "\t\t"); area.append(find.next() + "\t\t"); area.append(find.next() + "\t\t"); area.append(find.next() + '\n'); } else { find.next(); find.next(); find.next(); find.next(); } } file.close(); find.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e2) { e2.printStackTrace(); } } private void getSortOfChinese(String[] bll) { // TODO Auto-generated method stub } } class Type implements ActionListener { public static int z = 2; public static int y = 0; public JLabel Lname, Lsex, Lunit, Lhomephone, Lemail, Ltelephone, Lnote;//添加标签 public JTextField Tname = new JTextField(15), Thomephone = new JTextField(25), Temail = new JTextField(25),Ttelephone = new JTextField(25), Tunit = new JTextField(25); public Choice Csex = new Choice();//创建文本框 public JButton sure, cancel;//添加“确定”“取消”按钮 public JFrame frame = new JFrame("录入联系人信息");//面板标题 public Type() { Csex.addItem("男");//给列表框或组合框等具有列表的对象添加项目 Csex.addItem("女"); } public void Type() { Container c = frame.getContentPane();//创建容器 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//单击窗口的关闭按钮时程序执行的操作 frame.setSize(800, 400);//窗口大小 frame.setLayout(new GridLayout(7, 2, 7, 7));//设置用户界面上的屏幕组件的格式布局 frame.setVisible(true);//设置面板可见 //获取你的屏幕的宽和高 int width = Toolkit.getDefaultToolkit().getScreenSize().width; int height = Toolkit.getDefaultToolkit().getScreenSize().height; //然后设置你编写的窗口的初始位置,也就是在中间, frame.setLocation(width / 2 - 200, height / 2 - 150); Lname = new JLabel("姓名");//标签 Lsex = new JLabel("性别"); Lunit = new JLabel("单位"); Lhomephone = new JLabel("住宅电话"); Lemail = new JLabel("Email"); Ltelephone = new JLabel("移动电话"); sure = new JButton("确定"); cancel = new JButton("取消"); JPanel pane1 = new JPanel();//添加面板 JPanel pane2 = new JPanel(); JPanel pane3 = new JPanel(); JPanel pane5 = new JPanel(); c.add(pane1);//将面板添加到容器中 c.add(pane2); c.add(pane3); c.add(pane5); pane1.add(Lname);//将标签添加到面板 pane1.add(Tname); pane1.add(Lsex); pane1.add(Csex); pane2.add(Lunit); pane2.add(Tunit); pane2.add(Lhomephone); pane2.add(Thomephone); pane3.add(Lemail); pane3.add(Temail); pane3.add(Ltelephone); pane3.add(Ttelephone); pane5.add(sure); pane5.add(cancel); sure.addActionListener(new ActionListener() // 设置监听器 { public void actionPerformed(ActionEvent e) // 用匿名内部类实现监听器 { if (Tname.getText().equals(""))//输入的姓名是否为空 /* * 显示一个错误对话框,该对话框显示的 message 为 'alert': * JOptionPane.showMessageDialog(null, "alert", * "alert", JOptionPane.ERROR_MESSAGE); */ JOptionPane.showMessageDialog(null, "录入失败姓名必须填写", "录入结果", JOptionPane.INFORMATION_MESSAGE); else { try { FileWriter AddressBook = new FileWriter("D:\\AddressBook.txt", true);//写入文件 PrintWriter add = new PrintWriter(AddressBook); String s1, s2, s3,s4; if (Tunit.getText().equals(""))//未输入数据 s1 = "无"; else s1 = Tunit.getText(); if (Thomephone.getText().equals("")) s2 = "无"; else s2 = Thomephone.getText(); if (Temail.getText().equals("")) s3 = "无"; else s3 = Temail.getText(); if (Ttelephone.getText().equals("")) s4 = "无"; else s4 = Ttelephone.getText(); add.println(Tname.getText()+ "\t" + Csex.getSelectedItem() + "\t" + s1 + "\t\t" + s2 + "\t\t" + s3 + "\t\t" + s4); add.close(); AddressBook.close(); z = 1; } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (y == 0) { JOptionPane.showMessageDialog(null, "录入成功", "录入结果", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "修改成功", "修改结果", JOptionPane.INFORMATION_MESSAGE); } Tname.setText(""); //删除时传入空白串 Tunit.setText(""); Thomephone.setText(""); Temail.setText(""); Ttelephone.setText(""); } } }); cancel.addActionListener(new ActionListener() // 设置监听器 { public void actionPerformed(ActionEvent e) // 用匿名内部类实现监听器 { frame.dispose();//关闭面板 z = 0; } }); } public void actionPerformed(ActionEvent e) { new Type().Type(); } }
相见恨晚的超实用网站
搞学习 知乎:www.zhihu.com 简答题:http://www.jiandati.com/ 网易公开课:https://open.163.com/ted/ 网易云课堂:https://study.163.com/ 中国大学MOOC:www.icourse163.org 网易云课堂:study.163.com 哔哩哔哩弹幕网:www.bilibili.com 我要自学网:www.51zxw
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
引言 本文主要是记录一下面试字节跳动的经历。 三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时
开源一个功能完整的SpringBoot项目框架
福利来了,给大家带来一个福利。 最近想了解一下有关Spring Boot的开源项目,看了很多开源的框架,大多是一些demo或者是一个未成形的项目,基本功能都不完整,尤其是用户权限和菜单方面几乎没有完整的。 想到我之前做的框架,里面通用模块有:用户模块,权限模块,菜单模块,功能模块也齐全了,每一个功能都是完整的。 打算把这个框架分享出来,供大家使用和学习。 为什么用框架? 框架可以学习整体
源码阅读(19):Java中主要的Map结构——HashMap容器(下1)
(接上文《源码阅读(18):Java中主要的Map结构——HashMap容器(中)》) 3.4.4、HashMap添加K-V键值对(红黑树方式) 上文我们介绍了在HashMap中table数组的某个索引位上,基于单向链表添加新的K-V键值对对象(HashMap.Node&lt;K, V&gt;类的实例),但是我们同时知道在某些的场景下,HashMap中table数据的某个索引位上,数据是按照红黑树
c++制作的植物大战僵尸,开源,一代二代结合游戏
    此游戏全部由本人自己制作完成。游戏大部分的素材来源于原版游戏素材,少部分搜集于网络,以及自己制作。 此游戏为同人游戏而且仅供学习交流使用,任何人未经授权,不得对本游戏进行更改、盗用等,否则后果自负。 目前有六种僵尸和六种植物,植物和僵尸的动画都是本人做的。qq:2117610943 开源代码下载 提取码:3vzm 点击下载--&gt; 11月28日 新增四种植物 统一植物画风,全部修
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
Python——画一棵漂亮的樱花树(不同种樱花+玫瑰+圣诞树喔)
最近翻到一篇知乎,上面有不少用Python(大多是turtle库)绘制的树图,感觉很漂亮,我整理了一下,挑了一些我觉得不错的代码分享给大家(这些我都测试过,确实可以生成喔~) one 樱花树 动态生成樱花 效果图(这个是动态的): 实现代码 import turtle as T import random import time # 画樱花的躯干(60,t) def Tree(branch
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
深度学习图像算法在内容安全领域的应用
互联网给人们生活带来便利的同时也隐含了大量不良信息,防范互联网平台有害内容传播引起了多方面的高度关注。本次演讲从技术层面分享网易易盾在内容安全领域的算法实践经验,包括深度学习图
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
Python 编程实用技巧
Python是一门很灵活的语言,也有很多实用的方法,有时候实现一个功能可以用多种方法实现,我这里总结了一些常用的方法,并会持续更新。
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
"狗屁不通文章生成器"登顶GitHub热榜,分分钟写出万字形式主义大作
前言 GitHub 被誉为全球最大的同性交友网站,……,陪伴我们已经走过 10+ 年时间,它托管了大量的软件代码,同时也承载了程序员无尽的欢乐。 上周给大家分享了一篇10个让你笑的合不拢嘴的Github项目,而且还拿了7万+个Star哦,有兴趣的朋友,可以看看, 印象最深刻的是 “ 呼吸不止,码字不停 ”: 老实交代,你是不是经常准备写个技术博客,打开word后瞬间灵感便秘,码不出字? 有什么
推荐几款比较实用的工具,网站
1.盘百度PanDownload 这个云盘工具是免费的,可以进行资源搜索,提速(偶尔会抽风????) 不要去某站买付费的???? PanDownload下载地址 2.BeJSON 这是一款拥有各种在线工具的网站,推荐它的主要原因是网站简洁,功能齐全,广告相比其他广告好太多了 bejson网站 3.二维码美化 这个网站的二维码美化很好看,网站界面也很...
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
相关热词 c# plc s1200 c#里氏转换原则 c# 主界面 c# do loop c#存为组套 模板 c# 停掉协程 c# rgb 读取图片 c# 图片颜色调整 最快 c#多张图片上传 c#密封类与密封方法
立即提问