java mvc

mvc,初次看十分复杂,不懂为什么要建那么多的包。现在回想,是十分的简单的。个人觉得建包的主要的作用是将项目的各个的部分细化,便于编程,便于程序的维护,便于调试。就像我们编写一个html页面一样,一上来我们就会在文件夹里建上style,inages,js这样的包一样。只要你知道一些基础的servlet知识,就很简单。

关键步奏,写一个jsp页面(form表单,每一个表单需要一个那么属性,便于servlet取值),新建servlet(针对要处理的功能,给servlet命名),在servlet中用request.getParameter("xxx");获取值,‘xxx’代表表单的那么属性的value。取得值后就要练数据库了,可以讲一个dbhelper类,注意要导入数据库的驱动sqljdbc4.jar。至于dbhelper类网上有源码。

在编写dao层,对数据库进行操作,可以在函数的头部就new 出dbhelper类的对象

private Connection conn;
 private PreparedStatement pstmt;
 private ResultSet rs;

 Dbhelper db = new Dbhelper();

对数据库的增删改查操作

 

 

总结:需求分析,设计表(sql),在eclipse中建包,导入jar包,编程,测试,编程。。。。

会用到的代码:

request.getParameter("xxx");

response.sendRedirect("xxx.jsp");

request.setAttribute(”name“, o);

request.getAttribute(“name”);

request.getRequestDispatcher("xxx.jsp").forward(request,response);

注意》》》在jsp中取request.getAttribute(“name”);时要将name加上双引号,不加jsp不报错的。

 

 


 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java实现一个模型、两个视图和两个控制器的功能软件,即采用MVC模式或者说是观察者模式,本程序通过输入球体半径,显示球体形状,面积体积等 Sphere.java package Model; import java.util.Observable; public class Sphere extends Observable { private double radius;//球体半径 private double area;//球体面积 private double volume;//球体体积 public Sphere() { radius=100d; area=4*Math.PI*Math.pow(radius, 2); volume=4*Math.PI*Math.pow(radius, 3)/3; } public double getRadius() { return radius; } public double getArea() { return area; } public double getVolume() { return volume; } public void setRadius(double radius) { this.radius = radius; this.area = 4*Math.PI*Math.pow(radius, 2); this.volume=4*Math.PI*Math.pow(radius, 3)/3; this.setChanged(); this.notifyObservers(); } } textView.java package View; import java.util.Observer; import java.util.Observable; import java.text.NumberFormat; import javax.swing.*; import Controller.TextController; import Model.Sphere; import java.awt.*; import java.awt.event.*; public class TextView extends JPanel implements Observer { private JLabel radiusLab;//提示用户输入球体半径 private JTextField radiusTextField;//接受用户输入球体半径 //private JLabel radiusRang; private JLabel areaLab;//显示球体面积 private JTextField areaTextField;//显示输入球体半径对应的面积 private JLabel volumeLab;//显示球体体积 private JTextField volumeTextField;//显示输入球体半径对应的体积 public TextView() { try { Init(); } catch(Exception e) { e.printStackTrace(); } } private void Init() throws Exception { radiusLab=new JLabel("球体半径"); radiusLab.setForeground(new Color(0,165,168)); //radiusRang=new JLabel("[0-200]"); radiusTextField = new JTextField(12); radiusTextField.setForeground(new Color(223,100,158)); radiusTextField.setBackground(new Color(210,204,230)); areaLab=new JLabel("球体面积"); areaLab.setForeground(new Color(0,165,168)); areaTextField = new JTextField(12); areaTextField.setBackground(new Color(193,219,219)); areaTextField.setEditable(fal
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值