【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中完成某个任务 ...
随机推荐
- python正则匹配次数,贪婪和非贪婪
贪婪模式 {m,n}表示匹配子串的次数>=m and <=n,再此分为内匹配次数尽可能的多 贪婪模式 {,n}表示 >=0 and <=n 贪婪模式 {m,} 表示> ...
- ASP.NET/C# Razor视图引擎深入浅出
在ASPX中我们使用 <% %>在里面编写C#代码在Razor中我们将会使用@{}编写C#代码1.基础——@+属性显示计算1+2的值:<span>1+2=@(1+2)</ ...
- jquery ajax获取后台数据后无法输出
今天做ajax获取数据,再浏览器的debugger窗口也看到了数据 ajax代码 $('#userSearch').click(function(){ $.get("loadAllUsers ...
- C# 委托实例实现的多种类型
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 数据库备份与还原:mysqldump,source
*数据库备份* 1.备份方法一:适用于myslam表: 直接将tb_name.frm.tb_name.myd.tb_name.myi三个文件保存,备份即可. 需要的时候直接解压到,移动到相应的数据库目 ...
- 【C语言】分别用下标法,地址法和指针法输出数组中的全部元素
#include<stdio.h> int main() { ] = { ,,,, }; int i, * p; printf("下标法:\n"); ; i < ...
- 在linux里面ps -ef | grep tomcat 什么意思
linux中的查看和tomcat有关系的进程的命令 例如 [root@localhost bin]# ps -eaf | grep tomcat root 5091 1 0 23:04 pts/0 0 ...
- 解密国内BAT等大厂前端技术体系-美团点评之下篇(长文建议收藏)
引言 在上篇中,我已经介绍了美团点评的业务情况.大前端的技术体系,其中大前端的技术全景图如下: 上篇重点介绍了工程化和代码质量的部分,工程化涵盖了客户端持续集成平台-MCI.全端监控平台-CAT.移动 ...
- 2019年小结&2020年展望
每篇一句 If you want love, then this is it. This is real life. It's not perfect but it's real. --Before ...
- 《实战Java高并发程序设计》读书笔记四
第四章 锁的优化及注意事项 1.锁性能的几点建议 减小锁持有时间: 系统持有锁时间越长锁竞争程度就越激烈,只对需要同步的方法加锁,可以减小锁持有时间进而提高锁性能. 减少锁的持有时间有助于降低锁冲突的 ...