急急急求助求助

QEC568320642 2012-04-02 11:24:22
在客户端我是这么写的问题出在性别上在后台得到的值总是on怎么回事请高手指点
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册页</title>
</head>
<body>
<form action="RegisterServlet" method="post">
<table border="1" align ="center">
<tr>
<td>用户名</td>
<td> <input type="text" name="username"></td>
</tr>
<tr>
<td>密码</td>
<td> <input type ="password" name="userpass"></td>
</tr>
<tr>
<td>
男 <input type ="radio" value="male" name="sex" checked>
</td>
<td>
女 <input type ="radio" value="female" name="sex">
</td>
</tr>
<tr>
<td> <input type ="submit" value="提交"> </td>
</tr>
</table>
</form>

在后台是这么接受的
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String username = request.getParameter("username");
String userpass = request.getParameter("userpass");
String gender = request.getParameter("sex");
System.out.println(gender);//这里怎么得到的值是on啊请给提示
...全文
122 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
colie_li 2012-04-03
  • 打赏
  • 举报
回复
额...看了好久才看懂什么意思,你的那个“3”确定数据库里有吗,一般不这么写,通过游标把数据查出来存在一个变量里面这样的话试试 看看还有没有错...
QEC568320642 2012-04-03
  • 打赏
  • 举报
回复
我还有一个问题在客户端我是这么写的
<form action="LoginServlet" method="post">
<table border="1" align ="center">
<tr>
<td>用户名</td>
<td> <input type="text" name="username"></td>
</tr>
<tr>
<td>密码</td>
<td> <input type ="password" name="userpass"></td>
</tr>
<tr>
<td> <input type ="submit" value="登录"> </td>
<td> <a href="Register.jsp"> 免费 <form action="LoginServlet" method="post">
<table border="1" align ="center">
注册</a> </td>
</tr>
</table>
</form><form action="LoginServlet" method="post">
<table border="1" align ="center">
<tr>
<td>用户名</td>
<td> <input type="text" name="username"></td>
</tr>
<tr>
<td>密码</td>
<td> <input type ="password" name="userpass"></td>
</tr>
<tr>
<td> <input type ="submit" value="登录"> </td>
<td> <a href="Register.jsp"> 免费 <form action="LoginServlet" method="post">
<table border="1" align ="center">
注册</a> </td>
</tr>
</table>
</form>
在后台我登录一个人我保证数据库里有这个人可
out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
怎么一写上rs.getString(3)网页就不显示不写时前两项没错网页正常显示
hubing0316 2012-04-03
  • 打赏
  • 举报
回复
这里改了再试试
<td>
男 <input type ="radio" value="male" name="sex" checked>
</td>
<td>
男 <input type ="radio" value="male" name="sex" checked="checked" >
</td>
colie_li 2012-04-03
  • 打赏
  • 举报
回复
恩 它俩没区别
QEC568320642 2012-04-03
  • 打赏
  • 举报
回复
但我发现cheecked和checked=“checked”没有什么区别啊
colie_li 2012-04-03
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

恩真 是怪事现在运行有好了我也没改动
请问一下 男 <input type ="radio" value="male" name="sex" checked>
中cheecked和checked=“checked”有什么区别啊
[/Quote]
基本上没什么用,只是有cheecked的话出现这个页面的时候默认为男;你可以试下....
QEC568320642 2012-04-03
  • 打赏
  • 举报
回复
恩真 是怪事现在运行有好了我也没改动
请问一下 男 <input type ="radio" value="male" name="sex" checked>
中cheecked和checked=“checked”有什么区别啊
colie_li 2012-04-03
  • 打赏
  • 举报
回复
楼主再改动的前台的时候刷新下浏览器在测试,改变类的话重启下服务器.....
colie_li 2012-04-03
  • 打赏
  • 举报
回复
运行了下 满足你的要求:

<body>
<form action="Login" method="post">
<table border="1" align ="center">
<tr>
<td>用户名</td>
<td> <input type="text" name="username"></td>
</tr>
<tr>
<td>密码</td>
<td> <input type ="password" name="userpass"></td>
</tr>
<tr>
<td>
男 <input type ="radio" value="男" name="sex" checked>
</td>
<td>
女 <input type ="radio" value="female" name="sex">
</td>
</tr>
<tr>
<td> <input type ="submit" value="提交"> </td>
</tr>
</table>
</form>
</body>







import java.io.IOException;
import java.io.PrintWriter;

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

public class Login extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String username = request.getParameter("username");
String userpass = request.getParameter("userpass");
String gender = request.getParameter("sex");
System.out.println(gender);




}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}




菖蒲老先生 2012-04-03
  • 打赏
  • 举报
回复
在前台显示的效果虽然是一样的,可能后台解析的时候标准不一样吧。

[Quote=引用 4 楼 的回复:]

虽然打印出结果啦但是是打印出的male而不是男啊我把value = "male"改成了value = “男" 还是老样子打印的是male请赐教
还有为什么
td>
男 <input type ="radio" value="male" name="sex" checked>
</td>
写成
<td>
男 <input type ="radio" value="mal……
[/Quote]
QEC568320642 2012-04-03
  • 打赏
  • 举报
回复
虽然打印出结果啦但是是打印出的male而不是男啊我把value = "male"改成了value = “男" 还是老样子打印的是male请赐教
还有为什么
td>
男 <input type ="radio" value="male" name="sex" checked>
</td>
写成
<td>
男 <input type ="radio" value="male" name="sex" checked="checked" >
</td>
就能打印结果了呢上一个不同样都是被选中吗?请给细分析一下
QEC568320642 2012-04-03
  • 打赏
  • 举报
回复
我补充一下我已经把 男 <input type ="radio" value="男" name="sex" checked = "checked">
value的值改成男了但输出的仍然是male
QEC568320642 2012-04-03
  • 打赏
  • 举报
回复
虽然不出on了但打印出来的总是male和female我想让它是中文的男和女该怎么解决啊??请指点虽然出结果啦但我还是不太明白为什么写上checked="checked"就不打印on了呢同样是都被选中了啊请帮忙细分析一下
QEC568320642 2012-04-03
  • 打赏
  • 举报
回复
请问我的列数明明是username,userpass,sex三列为什么运行是说没有第三列呢
QEC568320642 2012-04-03
  • 打赏
  • 举报
回复
没错啊我把程序让你看看吧
<%--
Document : index
Created on : 2012-4-2, 20:07:19
Author : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录首页</title>
</head>
<body>
<form action="LoginServlet" method="post">
<table border="1" align ="center">
<tr>
<td>用户名</td>
<td> <input type="text" name="username"></td>
</tr>
<tr>
<td>密码</td>
<td> <input type ="password" name="userpass"></td>
</tr>
<tr>
<td> <input type ="submit" value="登录"> </td>
<td> <a href="Register.jsp"> 免费注册</a> </td>
</tr>
</table>
</form>

</body>
</html>

后台是
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dljt;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Administrator
*/
@WebServlet(name = "LoginServlet", urlPatterns = {"/LoginServlet"})
public class LoginServlet extends HttpServlet {

/**
* Processes requests for both HTTP
* <code>GET</code> and
* <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String username = request.getParameter("username");
String userpass = request.getParameter("userpass");
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String Driver = "org.apache.derby.jdbc.ClientDriver";
String url = "jdbc:derby://localhost:1527/sample";
String user = "app";
String pass = "app";
String sql = "select username,userpass from QQ where username = '"+username+"'and userpass ='"+userpass+"'";

try {
Class.forName(Driver);
conn = DriverManager.getConnection(url, user, pass);
st = conn.createStatement();
rs = st.executeQuery(sql);
if(rs.next()) {
out.println(rs.getString("USERNAME")+" "+rs.getString("USERNAME")+" "+rs.getString("SEX"));
}else {
out.println("<script language = Javascript>");
out.println("window.alert(\"用户不存在请注册\")");
out.println("</script>");
request.getRequestDispatcher("Login.jsp").include(request, response);
}
} catch (SQLException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
} finally {
out.close();
try {
rs.close();
st.close();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
}

}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP
* <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP
* <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

数据库里有三个列分别是username,userpass,sex我是用的netbeans直接复制过去看看哪里有错啊切数据库里已有一个记录登录就是查不出他的信息这到底是怎么回事呢

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧