首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

新手请问

2012-03-25 
新手请教%@ page languagejava importjava.util.* pageEncodingutf-8%%String path request

新手请教
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>用户注册页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function kkc(){
var biaodan=document.getElementById("biaodan");
var name=document.getElementById("name");
var password=document.getElementById("password");
var pwd=document.getElementById("pwd");
if (null == name || "".equals(name)) {
out.print("用户名不能为空!!");
return;
}
  if (null == password || "".equals(password)) {
out.print("密码不能为空!!");
return;
}
if (null == pwd || "".equals(pwd)) {
out.print("确认密码不能为空!!");
return;
}

if (!pwd.equals(pwd)) {
out.println("两次密码不正确!");
return;
}

}
  biaodan.submit();
}
</script>
  </head>
  
  <body>
  <H3 align=center><FONT size=7 face=楷体_GB2312>欢迎您注册本系统,感谢您的到来!</FONT></H3>
  <form action="t1" id="biaodan" name="biaodan" method="get">
   
  <input type="text" id="name" name="name" value="请输入您的帐号"/>
  <br> 
   
  <input type="text" id="password" name="password" value="请输入密码"/>
  <br>
   
  <input type="text" id="pwd" name="pwd" value="请再次输入密码"/>
  <br> 
  <input type="button" id="button" name="button" onclick="kkc()" value="点击注册"/>
  <input type="reset" id="chongzhi" name="chongzhi" value="信息重置"/>
   
  </form>
  </body>
</html>






<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
<servlet-name>t1</servlet-name>
<servlet-class>key.t1</servlet-class>
  </servlet>
  <servlet-mapping>
<servlet-name>t1</servlet-name>
<url-pattern>/t1</url-pattern>
  </servlet-mapping>


  
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>



package key;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class t1 extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(req, resp);
}

}
为什么后台捕获不到前台传递的值呢。。。才学JAVA 不是很懂

[解决办法]
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub

String name = req.getParameter("name") ;
String password = req.getParameter("password") ;

String pwd = req.getParameter("pwd") ;

System.out.println("name = " + name + ", password = " + password + " , pwd = " + pwd) ;

}

热点排行