编写SSH框架碰到的问题

1.用户提交表单时,action类并没有接受到表单中的数值,系统提示
这里写图片描述

出现这种情况时可以检测一下action类的名字,是否命名一致,还有一种情况很容易忘记,就是接受表单的实体类忘记了写它的get(),set()方法,截图如下:

这里写图片描述

如图有可能缺少这两种方法

这里写图片描述

2.出现了调用DAO类的方法出现并未能获取到该数据,实例如下:

这里写图片描述

这种情况是有可能applicatinContext.xml中beans的命名空间以及Schema的编码方式未进行更改,改成:

<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="   
  http://www.springframework.org/schema/aop     
  http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
  http://www.springframework.org/schema/beans     
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
  http://www.springframework.org/schema/context   
  http://www.springframework.org/schema/context/spring-context-2.5.xsd   
  http://www.springframework.org/schema/tx     
  http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName">
    <context:annotation-config />
    <context:component-scan base-package="*" />

改成这样可以解决该问题。

3.当你觉得你部署的SSH框架没问题,但是出现了

这里写图片描述

 <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>

需要在web.xml文件中添加这么一段代码,这段代码设置了spring的监听器,可以让项目读到applicationContext.xml

4.如果想显示如下

这里写图片描述

实现一行的修改时,我们要读取到这行数据的主键ID时,删除为在同一个页面,我们显示数据是通过s标签获得,jsp页面实现删除如下:

<s:iterator value="personList" var="varname">
        <s:property value="id"/>
        <s:property value="name"/><a href="delete?person.id=<s:property value="id"/>">删除</a><a href="update.jsp?id=<s:property value="id"/>">修改</a>
        <br>
    </s:iterator>

修改是跳到另外一个页面,就要设计变量在不同jsp页面的传递,我们在其跳转的链接加入

?id=<s:property value="id"/>

在另外一个页面获取

String id = request.getParameter("id");

将其加入到相应的action中,

<form action="update?person.id=<%=id%>" method="post">
        请输入要修改成为的name:<input type="text" name="person.name"/>
        <br>
        <input type="submit" name="submit" value="修改"/>
    </form>

使用s标签则需要使用

<%@taglib prefix="s" uri="/struts-tags"%>

5.用户在jsp页面输入表单,在数据库中显示为乱码,例如

这里写图片描述

需要在applicationContext.xml中修改连接方式

<property name="url"
            value="jdbc:mysql://localhost:3306/idname?characterEncoding=UTF-8">
        </property>

添加characterEncoding=utf-8即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值