<a href="showStudenInfByIsRegister.action?student.isRegister=1">已注册——按类别显示学生信息</a> 问题是这样的:上面的语句是在jsp中 我想把isRegisterisRegister=1的值传到对应的action中但是我在日志输出isRegister的值时发现所出错的值是0(System.out.println("isRegister 的值为: "+student.getIsRegister());也就是说无法将jsp页面中设定的值传递到action中。
大家看下如何解决?JSP

解决方案 »

  1.   

    你这种方式是通过get方式提交数据,那么你在action中用这种方式试一试 String[] temp =(String []) 
         ActionContext.getContext().getParameters().get("student.isRegister");
       
     int isRegister = Integer.parseInt(temp[0]);
      

  2.   

    你用的是struts1还是struts2?
    "isRegister 的值为: "+student.getIsRegister():
    里面的student是new出来的还是怎么来的
      

  3.   

    这个不应该是直接request.getParameter("student.isRegister");来得到传过来的值么?get的一个参数而已,没有被action再自动封装到student的属性中去吧
      

  4.   


    这个是在自己定义的student类中生成的get方法;我用的struts2。
      

  5.   


    我把你的代码复制到我的action中,并导入相应的包,启动tomcat时出错。
      

  6.   

    启动tomcat出错,把错误信息贴上来
      

  7.   


    2013-4-12 11:40:06 org.apache.catalina.core.AprLifecycleListener init
    信息: Loaded APR based Apache Tomcat Native library 1.1.16.
    2013-4-12 11:40:06 org.apache.catalina.core.AprLifecycleListener init
    信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
    2013-4-12 11:40:06 org.apache.coyote.http11.Http11AprProtocol init
    信息: Initializing Coyote HTTP/1.1 on http-8080
    2013-4-12 11:40:06 org.apache.coyote.ajp.AjpAprProtocol init
    信息: Initializing Coyote AJP/1.3 on ajp-8009
    2013-4-12 11:40:06 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 492 ms
    2013-4-12 11:40:06 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2013-4-12 11:40:06 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/6.0.20
    2013-4-12 11:40:07 org.apache.catalina.core.ApplicationContext log
    信息: Initializing Spring root WebApplicationContext
    log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    log4j:WARN Please initialize the log4j system properly.
    2013-4-12 11:40:10 org.apache.catalina.core.StandardContext listenerStart
    严重: 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 'showStudenInfByIsRegisterAction' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.mytest.action.Student.ShowStudentInfByIsRegisterAction]: Constructor threw exception; nested exception is java.lang.NullPointerException
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.mytest.action.Student.ShowStudentInfByIsRegisterAction]: Constructor threw exception; nested exception is java.lang.NullPointerException
    Caused by: java.lang.NullPointerException
    at com.mytest.action.Student.ShowStudentInfByIsRegisterAction.<init>(ShowStudentInfByIsRegisterAction.java:17)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:85)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:757)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:722)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:386)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    2013-4-12 11:40:10 org.apache.catalina.core.StandardContext start
    严重: Error listenerStart
    2013-4-12 11:40:10 org.apache.catalina.core.StandardContext start
    严重: Context [/basicFunction] startup failed due to previous errors
    2013-4-12 11:40:10 org.apache.catalina.core.ApplicationContext log
    信息: Closing Spring root WebApplicationContext
    2013-4-12 11:40:10 org.apache.catalina.core.ApplicationContext log
    信息: Initializing Spring root WebApplicationContext
    log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    log4j:WARN Please initialize the log4j system properly.
    AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool@1890e38)
       LogAbandoned: true
       RemoveAbandoned: true
       RemoveAbandonedTimeout: 180
    2013-4-12 11:40:16 org.apache.coyote.http11.Http11AprProtocol start
    信息: Starting Coyote HTTP/1.1 on http-8080
    2013-4-12 11:40:16 org.apache.coyote.ajp.AjpAprProtocol start
    信息: Starting Coyote AJP/1.3 on ajp-8009
    2013-4-12 11:40:16 org.apache.catalina.startup.Catalina start
    信息: Server startup in 10014 ms运行后的结果如上所示。(我这里补充说明下: 在数据库里面 isregister 这个属性我是有设置默认值为0,也就是只能把默认值传到action里面,其实我的这种做法已经有实现过,但不知道这次怎么调试就是没有办法把jsp页面的值传过来。)
      

  8.   

    Caused by: java.lang.NullPointerException
    at com.mytest.action.Student.ShowStudentInfByIsRegisterAction.<init>(ShowStudentInfByIsRegisterAction.java:17)错误原因, 在你这个类com.mytest.action.Student.ShowStudentInfByIsRegisterAction第17行空指针异常,你检查下你的action里时候有Service的set方法,以及applicationcontext.xml中时候建立action与service的依赖。
    如果还没解决,吧action这个类的17行所在的方法放出来,