【Javaweb】Servlet的xml和注解配置
1.xml
<%@ page language="java" contentType="text/html;"
%>
<!DOCTYPE html>
<html>
<head> <title>Insert title here</title>
</head>
<body>
<form name="form1" action="MyServlet">
user:<input name="user" type="text" id="user" size="25" maxlength="30"><br>
pass:<input name="password" type="password" id="password" size="25" maxlength="30"><br>
b<input type="submit" name="Sumbmit" value="提交"><br>
</form>
</body>
</html>
<servlet>
<servlet-name>form1</servlet-name>//这里是自定义的
<servlet-class>Try.MyServlet</servlet-class>//包名+servlet类名
</servlet>
<!-- servlet的虚拟路径的配置 -->
<servlet-mapping>
<servlet-name>form1</servlet-name>//要和上面匹配
<url-pattern>/MyServlet</url-pattern>//类名,注意“/”
</servlet-mapping>
package Try; import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
* Servlet implementation class MyServlet
*/
//@WebServlet("/MyServlet")
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public MyServlet() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(request, response);
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub System.out.println("Login success");
String username=request.getParameter("user");
String password=request.getParameter("password");
System.out.print("user:"+username+"\npassword"+password);
} }

2.注解
@WebServlet("/MyServlet")
未正式发布一般使用web.xml,利于调试
【Javaweb】Servlet的xml和注解配置的更多相关文章
- Servlet生命周期和注解配置
Servlet的生命周期和注解配置问题 /* Servlet? 运行在服务器上的小程序 定义浏览器访问到Tomcat的规则 一.生命周期? 1.创建 2.提供服务 3.被销毁 二.servlet3.0 ...
- Servlet(二)----注解配置
## Servlet3.0 * 好处: * 支持注解配置.可以不需要web.xml了. * 步骤: 1.创建JavaEE项目,选择Servlet的版本3.0以上,可以不创建web.xml 2. ...
- Servlet读取xml文件的配置参数
web.xml中数据库连接配置: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns: ...
- JAVA日记之mybatis-3一对一,一对多,多对多xml与注解配置
1.Mybatis多表查询1.1 一对一查询1.1.1 一对一查询的模型用户表和订单表的关系为,一个用户有多个订单,一个订单只从属于一个用户 一对一查询的需求:查询一个订单,与此同时查询出该订单所属的 ...
- mybatis学习一:基于xml与注解配置入门实例与问题
注:本case参考自:http://www.cnblogs.com/ysocean/p/7277545.html 一:Mybatis的介绍: MyBatis 本是apache的一个开源项目iBatis ...
- Servlet 3.0 使用注解配置URl提示404错误
我的环境是 Eclipse oxygen + Servlet 3.0 因为3.0已经开始使用注解了 之前我都是配置listenner 还有Servlet mapping 在 web.xml 中 就 ...
- 黑马Spring学习 AOP XML和注解配置 5种通知 切点切面通知织入
业务类 package cn.itcast.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoin ...
- Java Servlet详解(体系结构+注解配置+生命周期)
Java Servlet详解(注解配置+生命周期) 什么是Servlet : (Server applet)? 顾名思义:服务端的小程序 Servlet只是一个接口,定义了Java被浏览器访问到(To ...
- springAop:Aop(Xml)配置,Aop注解配置,spring_Aop综合案例,Aop底层原理分析
知识点梳理 课堂讲义 0)回顾Spring体系结构 Spring的两个核心:IoC和AOP 1)AOP简介 1.1)OOP开发思路 OOP规定程序开发以类为模型,一切围绕对象进行,OOP中完成某个任务 ...
随机推荐
- es7实现数学乘方
//math.pow简写方法 console.log(2 ** 6)
- Tomcat目录说明
apache-tomcat-x.x.xx bin:保存启动与监控Tomcat的命令文件的文件夹 conf:保存Tomcat配置文件的文件夹,如servlet.xml为服务器的主配置文件,web.xml ...
- kuangbin专题 专题九 连通图 Network UVA - 315
题目链接:https://vjudge.net/problem/UVA-315 题目:求割点. #include <iostream> #include <cstdio> #i ...
- 数据库程序接口——JDBC——API解读第一篇——建立连接的核心对象
结构图 核心对象 Driver Java通过Driver接口表示驱动,每种类型的数据库通过实现Driver接口提供自己的Driver实现类. Driver由属性,操作,事件三部分组成. 属性 公共属性 ...
- WKWebView 使用的坑
WKWebView 简介: WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView 组件,用以替代 UIKit 中笨重难用.内存泄漏的 UIWebView.WKWebView ...
- 解决MinGW运行时提示丢失libgmp-10.dll
如何解决刚安装的MinGW提示"丢失xxx.dll" 解决方案: 1.配置环境变量,出现这种问题的主要原因是因为没配置环境变量,网上的大多数解决方案也是基于这个的. 2.安装包损坏 ...
- iOS性能优化之内存(memory)优化
https://www.jianshu.com/p/8662b2efbb23 近期在工作中,对APP进行了内存占用优化,减少了不少内存占用,在此将经验进行总结和分享,也欢迎大家进行交流. 在优化的过程 ...
- 算法进阶:0x01 位运算
一.快速幂的模板代码 a^b%p: #include<iostream> using namespace std; int main() { int a,b,p; cin>>a ...
- 【JavaWeb】Spring入门——HelloWorld
0.为什么要使用Spring https://www.cnblogs.com/zmmi/p/7922186.html 1. 下载jar包 https://blog.csdn.net/qq_435401 ...
- 转:建立maven私服
一.下载安装与配置 下载 到官网下载:https://www.sonatype.com/download-oss-sonatype image.png 下载的是oss3.x版本的(当时最新版), ...