2023-07-18 16:09阅读: 5评论: 0推荐: 0

javaweb随记

javaweb记录

新建项目

整个项目新建时,只有一个src文件和web文件,web文件下有webinf文件

修改项目重要文件配置

点击project-structure中的module选项,可以看到创建的所有项目

点击facet 为项目添加模块

servlet

servlet获取数据,调用dao方法完成增删改查,dao也可以是后面使用的mapper

但是命名时,要继承HTTPservlet类 整个类在tomcat包内

点击project-structure中的module选项,点击dependency添加依赖

servlet相当于后面的controller

使用servlet获取参数时分别进行两种方法dopost 与 doget

@override
public void doPost(	Httpservlet request,Httpservlet resonse) throws servletexception,ioexception{
    
}

request.getparameter获取传过来的参数

将前端页面form表单的函数与后端servlet对应,需要在web.xml修改

图片2

接口实际上是一种规范用来定义需要操作的方法

dao数据访问对象 data access object

在写接口的具体实现时,使用impl继承接口

public class namedaoimpl extend basdao implements namedao{
    //重写接口内的方法
}

测试接口 新建junit test case

设置默认访问界面 可在tomcat 的web.xml文件里设置标签

405 当前请求方法不支持

空指针是是因为想对null进行格式化 例如 integer.parseInt()

调试 stepover 单步运行

servlet执行post方法存入到数据库时,为避免乱码 ,必须写在获取参数之前

request.setcharcterencoding("utf-8")

抽象类

java语言中,用abstract 关键字来修饰一个类时,这个类叫作抽象类。抽象类是它的所有子类的公共属性的集合,是包含一个或多个抽象方法的类。抽象类可以看作是对类的进一步抽象。在面向对象领域,抽象类主要用来进行类型隐藏。

为什么要用抽象类,什么情况下使用

1 无法完整描述一个类,只能抽象化概念来使用
2 子类写的方法重写父类的方法abstact。

servlet


设置servlet实例化顺序提前

配置web.xml和前后端的交互

一个servlet可以对应多个servletmapping,因为servlet里可以有多种服务,然后根据url的不同,选取不同服务

500:服务器(tomcat,ngix)内部错误

http

http是无状态,无法判断两次请求是同一客户端还是不同客户端,所以采用会话跟踪技术session解决

获取session

httpsession session=request.getsession();
session.getId();

服务器内部转发与重定向

内部转发

代码 类比
request 小货车
getRequestDispatcher("转发地址") 告诉司机要去哪
forward(request, response) 出发

重定向

response.sendRedirect("地址");

302:重定向

本文作者:jinganglang567

本文链接:https://www.cnblogs.com/tgfoven/p/17563299.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   jinganglang567  阅读(5)  评论(0编辑  收藏  举报
  1. 1 look after you louis tomlinson
  2. 2 just hold on louis tomlinson
  3. 3 i can steven cooper
  4. 4 rock me one direction
  5. 5 just can't let her go one direction
  6. 6 this town Niall Horan
  7. 7 cut in love july
  8. 8 nemo 夜愿
  9. 9 in the end Black Veil Brides
  10. 10 glad you came the wanted
  11. 11 chasing the sun the wanted
  12. 12 TAKE MY HAND simple plan
  13. 13 wish i had an angel 夜愿
just hold on - louis tomlinson
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Sasha Alex Sloan/Eric Rosse

作曲 : Steve Aoki/Louis Tomlinson/Sasha Alex Sloan/Nolan Lambroza/Eric Rosse

Wish that you could build a time machine

So you could see

The things no one can see

Feels like you're standing on the edge

Looking at the stars

And wishing you were them

What do you do when a chapter ends?

Do you close the book and never read it again?

Where do you go when your story's done?

You can be who you were or who you'll become

Oooh

If it all goes wrong

Oooh

Darling just hold on

The sun goes down and it comes back up

The world it turns no matter what

Oooh

If it all goes wrong

Darling just hold on

Oooh

Darling just hold on

Oooh

It's not over until it's all been said

It's not over until your dying breath

So what do you want them to say when you're gone?

That you gave up or that you kept going on?

What do you do when a chapter ends?

Do you close the book and never read it again?

Where do you go when your story's done?

You can be who you were or who you'll become

Oooh

If it all goes wrong

Oooh

Darling just hold on

The sun goes down and it comes back up

The world it turns no matter what

Oooh

If it all goes wrong

Darling just hold on

Oooh

Darling just hold on

Oooh

Oooh

If it all goes wrong

Oooh

Darling just hold on

Oooh

If it all goes wrong

Darling just hold on

点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起