代码赏析
jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
Sevelet:
package tt;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestA extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//设置接收的信息的字符集
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("name");
//设置输出的信息的格式及字符集
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control","no-cache");
//创建输出流
PrintWriter out=response.getWriter();
out.println("
");
if(name.equals("jack_booth")){
out.println(""+"对不起,此网名已注册!"+"");
}else{
out.println(""+"此网名可以注册!"+"");
}
out.println("");
out.close();
}
}
web.xml:
|
文件: |
TestAjax.rar |
大小: |
4KB |
下载: |
下载 | |
xmlns=""
xmlns:xsi=""
xsi:schemaLocation="
">
login
tt.TestA
login
/login
阅读(1418) | 评论(0) | 转发(0) |