博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2018.6.27 Ajax实现异步刷新
阅读量:4487 次
发布时间:2019-06-08

本文共 1639 字,大约阅读时间需要 5 分钟。

Servlet获取URL地址。在HttpServletRequest类里,有以下六个取URL的函数:

getContextPath 取得项目名 getServletPath 取得Servlet名 getPathInfo 取得Servlet后的URL名,不包括URL参数 getRequestURL 取得不包括参数的URL getRequestURI 取得不包括参数的URI,即去掉协议和服务器名的URL

相对应的函数的值如下:

getContextPath:/ServletTest getServletPath:/main getPathInfo:/index/testpage/test getRequestURL:http://localhost:8080/ServletTest/main/index/testpage/test getRequestURI:/ServletTest/main/index/testpage/test

验证用户名

package com.glut.demo;import java.io.IOException;import java.util.Arrays;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class ValidateUserName extends HttpServlet {        private static final long serialVersionUID = 1L;    public void doPost(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        System.out.println("aa");        List
usernames = Arrays.asList("AAA","BBB","CCC"); String username = request.getParameter("username"); System.out.println("aa"); String result = null; if(usernames.contains(username)){ result = "
该用户名已经被使用"; }else{ result = "
该用户名可以使用"; } response.setContentType("text/html"); response.getWriter().print(result); }}

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>      Ajax请求demo    
Username:

转载于:https://www.cnblogs.com/qichunlin/p/9231972.html

你可能感兴趣的文章
BZOJ4071: [APIO2015]八邻旁之桥
查看>>
Redis的六种特性 场景
查看>>
mysql 添加[取消]timestamp的自动更新
查看>>
码农的半衰期只有15年?
查看>>
手工释放linux内存
查看>>
2014-5-30 总结
查看>>
【H3 BPM工作流程管理产品小故事】第四篇 子表创建
查看>>
洛谷P1148 拱猪计分
查看>>
MySQL服务器的安装和配置,MySQL Workbench 8.0.12安装,MySQL的基本使用
查看>>
扑克序列
查看>>
java笔记--适配器模式的运用
查看>>
Replace Nested Conditional with Guard Clauses(用卫语句代替嵌套循环)
查看>>
jsp中${}是EL表达式的常规表示方式
查看>>
GoldenGate常见问题及处理
查看>>
Android JNI学习(五)——Demo演示
查看>>
java map合并_java 实现合并map示例Demo1
查看>>
java 8 string_String.join() --Java8中String类新增方法
查看>>
java 布局教程_java布局学习(新)
查看>>
你真的会写Java吗?
查看>>
alibaba.fastjson.JSONObject 解析
查看>>