SSH实例(5)

在src中新建struts.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.i18n.reload" value="true" />
    <constant name="struts.configuration.xml.reload" value="true" />
    <constant name="struts.custom.i18n.resources" value="globalMessages" />
    <constant name="struts.url.includeParams" value="none" />
    <constant name="struts.ui.theme" value="xhtml"></constant>
    <package name="struts2" extends="struts-default">
        <default-action-ref name="clasquery"></default-action-ref>
        <action name="clasquery" class="clasQueryAction">
            <result name="success">/query.jsp</result>
        </action>
        <action name="clas" class="clasAction">
            <result name="success" type="redirect">/clasquery.action</result>
        </action>
    </package>
</struts> 

ClasAction.java文件:

package com.school.action;

import com.school.entity.Clas;
import com.school.service.ClasService;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ClasAction extends ActionSupport {

    private ClasService clasService;
    public void setClasService(ClasService clasService) {
        this.clasService = clasService;
    }

    private Clas clas;
    public String execute(){
        Clas c=new Clas();
        c.setName(clas.getName());
        c.setComment(clas.getComment());
        clasService.saveClas(c);
        return SUCCESS;
    }

    public Clas getClas() {
        return clas;
    }

    public void setClas(Clas Clas) {
        this.clas = Clas;
    }
}

ClasQueryAction.java文件:

package com.school.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.school.entity.Clas;
import com.school.service.ClasService;

@SuppressWarnings("serial")
public class ClasQueryAction extends ActionSupport {

    private ClasService clasService;

    // 设置业务逻辑组件
    public void setClasService(ClasService clasService) {
        this.clasService = clasService;
    }

    public String execute(){
            List<Clas> claslist = clasService.findAll();
            // 将所有课程存放在request范围内
            ServletActionContext.getRequest().setAttribute("claslist", claslist);
            return SUCCESS;
    }

}
时间: 2024-10-19 03:17:34

SSH实例(5)的相关文章

python之socket-ssh实例

本文转载自大王http://www.cnblogs.com/alex3714/articles/5830365.html 加有自己的注释,应该会比原文更突出重点些 一. 基本Socket实例 前面讲了这么多,到底咋么用呢? 1 import socket 2 3 server = socket.socket() #获得socket实例 4 5 server.bind(("localhost",9998)) #绑定ip port 6 server.listen() #开始监听 7 pri

SSH实例(3)

src文件夹的结构如下: clasDao文件: package com.school.service; import java.util.List; import com.school.dao.ClasDAO; import com.school.entity.Clas; public class ClasServiceImpl implements ClasService{ private ClasDAO clasDAO; public void setClasDAO(ClasDAO Clas

SSH实例(2)

在WebContent\WEB-INF\下新建两个文件:applicationContext.xml和web.xml. 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

SSH实例(7)

运行结果. 浏览课程: 添加课程: 还有删除课程,这里就不演示了.

SSH实例(4)

Clas.hbm.xml文件如下: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <

SSH实例(6)

在WebContent文件夹下新建query.jsp和save.jsp文件. query.jsp: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "

SSH实例(1)

首先,配置struts.xml文件: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <st

Python 之 SSH实例(可接受大字节返回)

服务器端代码 #Author Kang import os import subprocess import socket server = socket.socket() server.bind(('localhost',9999)) server.listen() print("等待客户端连接:>>>>") while True: conn,addr = server.accept() print("接受了一个新的链接!!") while

SSH搭建完美CURD,含分页算法

今日开始研究使用java平台上的框架解决web服务端的开发. 这是一个完整的SSH实例,在马士兵老师的SSH整合代码基础上,增加用户的增删改查,同时实现structs方式的分页 放出源代码供大家学习参考.关键是网上的学习案例真少 http://pan.baidu.com/s/1ntHswHF