SSH 框架常见错误
新手学习SSH框架的时候总会遇到很多问题,一碰到404 或者500错误就不知道怎么解决。
404错误是很常见的一个错误,如果没有用框架基本上只可能是没有这个路径或者文件,但是用了框架之后404的原因就比较多了
404很有可能是struts配置,hibernate配置及其映射文件、applicationContext配置文件错误
首先是xml文件通不过校验,把xml文件拖到浏览器当中,如果通不过校验会提示你哪一行有问题
xml文件一定要嵌套,struts文件里面的action调用的方法一定要有,不然会报404或500错误
给一个struts配置给大家参考一下
<?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>
<package name="default" namespace="/" extends="struts-default">
<!-- stu --> <action name="list" class="com.hngc.action.CantonAction" method="list">
<result name="success">/listCanton.jsp</result>
</action> </package> </struts>
对应的action类如下
package com.hngc.action; import java.io.IOException;
import java.io.PrintWriter;
import java.util.List; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import com.hngc.entity.Canton; import com.hngc.service.BaseService;
import com.hngc.service.impl.CantonServiceImpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject; public class CantonAction extends ActionSupport {
private HttpServletRequest request= ServletActionContext.getRequest();//
private HttpServletResponse response= ServletActionContext.getResponse();
private BaseService<Canton> cantonService;
private Canton canton; public BaseService<Canton> getCantonService() {
return cantonService;
}
public void setCantonService(BaseService<Canton> cantonService) {
this.cantonService = cantonService;
}
public Canton getCanton() {
return canton;
}
public void setCanton(Canton canton) {
this.canton = canton;
} public String list() {
ActionContext context = ActionContext.getContext();
context.put("list", cantonService.list());
return SUCCESS;
}
public String save() {
ActionContext context = ActionContext.getContext();
cantonService.save(canton); return SUCCESS;
} }
要注意这里的 cantonService要和applicationContext里面的bean相对应,get set方法最好自动生成
有些人习惯拷贝之前的代码,忘记改get set方法名,这个网页会报500错误
canton 是实体类对象,需要get set方法,并且网页s标签也要对应,表单里面的name也要对应
1 <input name="canton.code" type="text" id="title" size="20">
hibernate配置一般不会出错,但是映射文件很容易写错
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4 <!--
5 Mapping file autogenerated by MyEclipse Persistence Tools
6 -->
7 <hibernate-mapping>
8 <class name="com.hngc.entity.Canton" table="canton" schema="dbo" catalog="LandDB">
9 <id name="code" type="java.lang.String">
10 <column name="code" />
11 <generator class="assigned" />
12 </id>
13 <property name="cname" type="java.lang.String">
14 <column name="cname" not-null="true" />
15 </property>
16 <property name="abb" type="java.lang.String">
17 <column name="abb" not-null="false" />
18 </property>
19 <property name="govName" type="java.lang.String">
20 <column name="govName" not-null="false" />
21 </property>
22 <property name="landName" type="java.lang.String">
23 <column name="landName" not-null="false" />
24 </property>
25 <property name="parentCode" type="java.lang.String">
26 <column name="parentCode" not-null="false" />
27 </property>
28 </class>
29 </hibernate-mapping>
这是一个完整的映射文件,容易错的地方有主键主键生产策略
<generator class="assigned" />
数据库字段可空,但是却写了 not-null="true"
类型不匹配 数据库字段为int t但是却写ype="java.lang.String
字段不匹配 <column name="parentCode" not-null="false" />
这个parentCode 是数据库中的字段
applicationContext的错误可以一个一个的注释掉测试
service action当中的get set方法要记得改名字,最好自动生成
这一期只是大概说一下错误的解决方法
之后后慢慢讲解具体的报错,有遇到问题的也可以留言
SSH 框架常见错误的更多相关文章
- SSH整合常见错误
spring+hibernate出错小结: (1)java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext ...
- ssh框架搭建错误集合
1,把jsp放入到WEB-INF/view目录下,struts2.xml配置<result name="success">/WEB-INF/view/home.jsp& ...
- SSH框架 通用 错误(404,500等)返回页面设置
在web.xml里面加入
- struts2.5框架使用通配符指定方法常见错误
struts2.5框架使用通配符指定方法(常见错误) 在学习struts框架时经常会使用到通配符调用方法,如下: <package name="shop" namespace ...
- eclipse使用SSH框架出现There is no Action mapped for namespace [/] and action name [] associated with context path错误
eclipse使用SSH框架出现There is no Action mapped for namespace [/] and action name [] associated with conte ...
- centos7:ssh免密登陆设置及常见错误
目录 一.免密登录设置 二.常见错误 三.CentOS7再ssh-copy-id时的错误 一.免密登录设置 1.使用root用户登录,进入到目录/root/.ssh 2.执行命令:ssh-keygen ...
- Python3环境安装Scrapy爬虫框架过程及常见错误
收录待用,修改转载已取得腾讯云授权 Scrapy安装介绍 Scrapy的安装有多种方式,它支持Python2.7版本及以上或Python3.3版本及以上.下面说明Python3环境下的安装过程. Sc ...
- 基于SSH框架的网上商城的质量属性
常见质量属性 1.性能 性能就是一个东西有多快,通常指响应时间或延迟. 响应时间:从发出请求到收到响应所用的时间,比如用户点击网页中的超链接或桌面应用程序中的按钮 延迟:消息从A点到B点,通过你的系统 ...
- 基于ssh框架开发的购物系统的质量属性
根据前面的博客,我们已经大致了解了ssh架构开发整体概念:Struts是一个实现了MVC模式的经典的框架:Hibernate是轻量级Java EE应用的持久层解决方案,以面向对象的方式提供了持久化类到 ...
随机推荐
- html的JavaScript的简单输入验证
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 3、Entity Framework Core 3.1入门教程-设定字段属性
本文章是根据 微软MVP solenovex(杨旭)老师的视频教程编写而来,再加上自己的一些理解. 视频教程地址:https://www.bilibili.com/video/BV1xa4y1v7rR ...
- Win 10 蓝屏,出现DRIVER_POWER_STATE_FAILURE的解决方法
笔者个人笔记本电脑,用的是华硕的飞行堡垒FZ系列,上个月装了个Ubuntu的系统,之后换回Windows后,电脑疯狂蓝屏,错误代码只有这个DRIVER_POWER_STATE_FAILURE.一开始我 ...
- VS2015+opencv3.1.0 imshow()函数出现中文乱码----问题一
Visual Studio提供高级保存选项功能,它能指定特定代码文件的编码规范和行尾所使用的换行符.在Visual Studio 2015中,该命令没有默认显示在“文件”菜单中.用户需要手工设置,才能 ...
- 每日JS逆向练习之斗鱼登录密码加密,今天你练了吗?
一切的基本功都是为后期调试滑块验证码准备的. 有兴趣的关注一下知识图谱与大数据公众号,当然不关注也无所谓.今天来看看斗鱼登录密码加密,正所谓熟能生巧,这种简单一点的基本3-5分钟就要能抠出来,有兴趣得 ...
- 【Android】AndroidStudio关于EventBus报错解决方法its super classes have no public methods with the @Subscribe
作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先说明,以前我用eventBus的 ...
- 初学WebGL引擎-BabylonJS:第4篇-灯光动画与丛林场景
前几章接触的案例都是接近静态的,由这张开始开始接触大量动态的内容,包括 球体灯光,变动的形体,以及一个虚拟的丛林场景 下章我会试着结合1-9案例的内容做出一个demo出来 [playground]-l ...
- Lua 调用的 C 函数保存 state 的两种方式: Storing State in C Functions 笔记
http://yanbin.is-programmer.com/posts/94214.html Registery的Key 1. 整数Key用于Lua的引用机制,所以不要使用整数作为Key 2. 通 ...
- Photogrammetry and Game
https://skulltheatre.wordpress.com/2013/02/11/photogrammetry-in-video-games-frequently-asked-questio ...
- 最通俗易懂的 Redis 架构模式详解
前言 话说有一名意大利程序员,在 2004 年到 2006 年间主要做嵌入式工作,之后接触了 Web,2007 年和朋友共同创建了一个网站,并为了解决这个网站的负载问题(为了避免 MySQL 的低性能 ...