【求助】JSP页面调用action方法,页面只能传参到Bean,action里面的方法不响应

apaulette 2017-08-05 08:45:51
求助各位大神!我刚开始入门,写了一个信息管理系统,用的Spring+Struts2+myBatis+Bootstrap界面。
我实现增.删.查的功能都正常,就改功能不行。但是,我改功能的代码和增功能的代码几乎一模一样。但是就是报错,我打调试信息看,发现增功能,可以正常从前台传参到Bean,再主动跳转到Action里面的add(),但是改功能就是不行,只能走到传参到Bean,但是没有跳转到update(),因为不跳转到update()处理,所以就报图一的错误。页面只有赋值取值,没有update()响应。
问题的关键就在于,add.jsp和update.jsp除了action关联的函数,<input>标签一个没有value先取值,一个有value取值之外,没有任何区别,真是没有区别,我还怕写错了,专门用BeyondCompare比对了,就<form action="">这个地方不一样,后附BC对比图。我试着把<form>里面的action从update改成add,也不行,改过之后就成add()不响应了,改成谁,谁不响应。
萌新学识疏浅,实在实在找不到哪里写错了,各位大神能不能指导一下!谢谢!
(如果放错版区了,还请版主帮忙更正一下,谢谢版主!)

代码如下:

BiYeXinXiAction:
..........
public String add() {
result = biYeXinXiService.insert(biYeXinXi);
backurl = "biYeXinXi/add.jsp";
return "result-jsp";
}
public String update() {
result = biYeXinXiService.update(biYeXinXi);
backurl = "front/biYeXinXi_intoUpdate.action?biYeXinXi.biyedanganid=" + biYeXinXi.getBiyedanganid();
return "result-jsp";
}
..........

add.jsp:写不下了,见附件图

update.jsp:写不下了,见附件图

struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.locale" value="zh_CN" />
<constant name="struts.multipart.maxSize" value="20971520" />
<constant name="struts.action.extension" value="action,do," />
<package name="front" extends="json-default" namespace="/front">
<action name="biyexinxi_*" class="biYeXinXiAction" method="{1}">
<result name="result-json" type="json">
<param name="root">result</param>
</result>
<result name="result-jsp">/biyexinxi/result.jsp</result>
<result name="index">/biyexinxi/index.jsp</result>
<result name="intoUpdate">/biyexinxi/update.jsp</result>
</action>
..............

springconfig.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>org.logicalcobwebs.proxool.ProxoolDriver</value>
</property>
<property name="url">
<value>proxool.db</value>
</property>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="typeAliasesPackage" value="com.bysmis" />
<property name="plugins">
<list>
<bean class="com.core.code.util.PagingPlugin">
<property name="dialect" value="mysql" />
</bean>
</list>
</property>
</bean>
<bean name="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.bysmis.persistence" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="myDataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>

bean.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<context:component-scan base-package="com.bysmis" />
</beans>







...全文
432 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
apaulette 2017-08-10
  • 打赏
  • 举报
回复
引用 4 楼 a276202031 的回复:
form 指定提交方式 method='post' 或者method='get'
和这个没有太大关系,我之前尝试了,不行。 目前看来,页面input标签,引入${xxx.xx}表达式的,只能用location=xxx.action跳转,没有表达式的,只能用submit()提交。 我想肯定是我哪里写错了,不然Java要是这么难用,那都没人用了。。。
apaulette 2017-08-10
  • 打赏
  • 举报
回复
引用 6 楼 zc881124 的回复:
出现那个错误,是因为提交的表单验证有问题。 表单提交过程出问题了,默认会跳转到input 看了下update.jsp 提交的name都为biYeXinXi 对象 不是应该为对应对象属性吗 你这样提交到后台取对象能取到值?应该和add.jsp 的name保持一致吗?
和后台JavaBean里面的属性是一致的。我比较不理解的是,为什么有的是form的submit(),有的是window.self.location跳转到action才能实现。。。不能统一成一种方法吗?
110成成 2017-08-09
  • 打赏
  • 举报
回复
出现那个错误,是因为提交的表单验证有问题。 表单提交过程出问题了,默认会跳转到input 看了下update.jsp 提交的name都为biYeXinXi 对象 不是应该为对应对象属性吗 你这样提交到后台取对象能取到值?应该和add.jsp 的name保持一致吗?
浮云若水 2017-08-09
  • 打赏
  • 举报
回复
controller中代码看不到不好分析
浮云若水 2017-08-09
  • 打赏
  • 举报
回复
form 指定提交方式 method='post' 或者method='get'
AlexMoonshadow 2017-08-08
  • 打赏
  • 举报
回复
这种问题一般都是小问题,但是又不容易发现,仔细检查下吧。
apaulette 2017-08-08
  • 打赏
  • 举报
回复
就没人能解释这个问题吗?!
apaulette 2017-08-05
  • 打赏
  • 举报
回复
有了新的进展! 把$(".form-horizontal").submit();改成window.self.location = "${contextPath}/front/biyexinxi_update.action";,竟然顺利通过了,请问为什么add.jsp里面可以submit(),update.jsp里面不可以,只能用重定向? 求大神解答原理,非常感谢!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧