package jsp.cotroller;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jsp.impl.Studentimpl;
import jsp.model.Student;
public class StudentSer extends HttpServlet {
Studentimpl studentimpl = new Studentimpl();
/**
* Constructor of the object.
*/
public StudentSer() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String status = request.getParameter("status");
if(status.equals("saveStudent")){
Student student = new Student();
String name = request.getParameter("sname");
String address = request.getParameter("saddress");
String[] hobby = request.getParameterValues("shobby");
String str = studentimpl.subString(hobby);
student.setName(name);
student.setAddress(address);
student.setHobby(str);
studentimpl.savaStudent(student);
}else if(status.equals("queryStudent")){
String sname = request.getParameter("sname");
request.getSession().setAttribute("sname", sname);
ArrayList<Student> students = studentimpl.queryStudent(sname);
request.setAttribute("studentparam", students);
RequestDispatcher dispatcher = request.getRequestDispatcher("/queryStudent.jsp");
dispatcher.forward(request, response);
}else if(status.equals("deleteStudent")){
int sid = Integer.parseInt(request.getParameter("sid"));
studentimpl.deleteStudent(sid);
String sname = request.getSession().getAttribute("sname").toString();
ArrayList<Student> students = studentimpl.queryStudent(sname);
request.setAttribute("studentparam", students);
RequestDispatcher dispatcher = request.getRequestDispatcher("/queryStudent.jsp");
dispatcher.forward(request, response);
//RequestDispatcher dispatcher = request.getRequestDispatcher("/queryStudent.jsp");
//dispatcher.forward(request, response);
}else if(status.equals("updateStudent")){
Student student = new Student();
String sid = request.getParameter("sid");
String name = request.getParameter("sname");
String address = request.getParameter("saddress");
String[] hobby = request.getParameterValues("shobby");
String str = studentimpl.subString(hobby);
student.setId(sid);
student.setName(name);
student.setAddress(address);
student.setHobby(str);
studentimpl.updateStudent(student);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
"完整简洁的jsp+servlet+jstl实例"是一个综合性的学习资源,旨在帮助初学者或希望深入理解JSP、Servlet和JSTL技术的开发者。这个实例集成了这三个关键技术,提供了一个可以直接运行的项目,使得学习者能够通过实践来掌握它们的工作原理和交互方式。 **JSP(JavaServer Pages)**是Java平台上的动态网页技术,它允许开发者在HTML代码中嵌入Java代码,从而实现服务器端的动态逻辑。在JSP中,可以定义脚本元素、声明元素、指令元素以及JSP标签,来处理请求和生成响应。JSP的执行过程包括翻译、编译和执行三个阶段,最终生成Servlet进行服务。 **Servlet**是Java EE中的核心组件,它是一个Java类,用于扩展服务器的功能。Servlet主要负责处理HTTP请求,生成HTTP响应,通常用于构建动态Web应用。Servlet生命周期包括加载、初始化、服务、销毁四个阶段,它们由容器(如Tomcat)管理。 **JSTL(JavaServer Pages Standard Tag Library)**是官方推荐的JSP标签库,它提供了一系列标准的标签,简化了JSP页面的开发,避免了过多的脚本代码。JSTL包含多个核心标签库,如Core、XML、JDBC、EL等,其中Core库是最常用的部分,包含了处理流程控制、输出、URL操作等功能。 在这个实例中,你可能会看到以下知识点的应用: 1. **JSP基本结构**:包括JSP页面的声明、脚本和指令元素的使用。 2. **JSP动作标签**:如`<jsp:include>`、`<jsp:forward>`等,用于页面组合和请求转发。 3. **JSTL Core库**:例如`<c:if>`条件判断,`<c:forEach>`循环,`<c:set>`设置变量等。 4. **EL(Expression Language)**:用于在JSP页面中简便地访问JavaBean属性和表达式计算。 5. **Servlet配置与映射**:在web.xml中配置Servlet,指定URL映射。 6. **Servlet生命周期**:了解如何初始化Servlet,处理请求,以及何时销毁。 7. **请求与响应处理**:学习如何在Servlet中获取请求参数,设置响应头和正文。 8. **MVC设计模式**:JSP作为视图,Servlet作为控制器,数据在两者之间传递,体现MVC模式。 9. **JSTL与EL的协同工作**:通过JSTL标签和EL表达式结合,使代码更清晰、可读性更强。 通过运行这个实例,你可以亲自动手实践这些概念,加深理解,并且快速掌握JSP、Servlet和JSTL的集成应用。记得在本地环境(如Tomcat服务器)部署"myjsp"项目,然后通过浏览器访问以观察效果,这将有助于巩固理论知识并提升实际操作技能。





























































- 1

- #完美解决问题
- #运行顺畅
- #内容详尽
- #全网独家
- #注释完整

- 粉丝: 2
- 资源: 6
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 智能家居_HomeAssistant_实战篇_教程文档_1741166831.zip
- 智能家居_知识集成_家庭管理_便捷生活_1741167623.zip
- 智能硬件_蓝牙键盘_多功能_控制系统_1741167267.zip
- sudo-wang_SmartHome_1741166971.zip
- 智能家居_IoT_MQTT_毕业设计_1741166964.zip
- VincentAzz_SmartHomeDashboard_1741167148.zip
- liar177_graduation_project_for_1741167072.zip
- 智能家居_开源软硬件系统_wumei-iot_学习与开发_1741167439.zip
- 智能家居_Zigbee_Android_管理控制系统_1741167232.zip
- guidons-master_HomeRPC_1741167209.zip
- 智能家居_语音交互_小蓝机器人_开源项目_1741166927.zip
- Java虚拟机-JVM面试题八股文PDF
- Maxscript实现小球碰撞反弹动画脚本源码下载
- 三菱FX PLC与变频器Modbus通讯实现设备控制与系统监测一体化,昆仑通态MCGS触摸屏辅助操作,功能多样适应性强 ,三菱PLC与三菱变频器Modbus通讯实用方案:采用FX1N PLC 485与
- 三菱PLC以太网通讯库与LabVIEW通讯库结合,三菱PLC以太网通讯MC 3E帧协议下的Labview通讯库设计与实现,三菱PLC 以太网通讯MC 3E帧协议labview通讯库 ,三菱PLC;
- 电信行业AI现状:2024年中国趋势调查报告


