问一下关于登陆页面的问题

低调小星 2014-06-08 03:27:32
今天照着参考书做一个jsp登陆页面的练习,页面成功显示,但是我点击按钮不会登陆
代码我是照着书打上去的 大家帮我看一下吧

login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<FROM id=vForm action='LoginC1' name=vForm method=post>
<DIV class=logoicon></DIV>
<DIV class=main_top>
<DIV class="title_note1 red link" id=login_err></DIV>
</DIV>
<DIV class=main_cen>
<p class=title>登陆</p>
<UL class=mainlogin>
<LI>
<DIV class="m1_1 f14">登陆名:</DIV>
<div class=ml_r>
<div class=inputbox><SPAN class=input><cite><input id=username tabIndex=0
alt=会员名:无内容/长度{4-64}/errArea{usernameErr} maxLength=64 name= username
autocomplete="off"></cite></SPAN></div><SPAN class="inputacc link"></SPAN>
<SPAN class="red link" id=usernameErr></SPAN></div>
<li>
<div class="ml_l f14">密码:</div>
<div class=ml_r>
<div class=inputbox><span class=input><cite><input id=password tabIndex=1 type=password maxLength=32 name=passwd>
</cite></span> </div><span class="inputacc link"><a>找回密码</a></span><span class="red link" id=passwordErr></span></div>
<li>
<div class=ml_l></div>
<div class=ml_r>
<div class=inputacc><LABEL for=savestate><INPUT id=savestate
onclick="document.getElementById('savestate_tip').style.display = this.checked?'block':'none';"
tabIndex=3 type=checkbox name=savestate> 记住登陆状态</LABEL></div>
<div class="inputtxt zi_9" id=savestate_tip
style="DISPLAY: none">建议在网吧/公用电脑上取消该选项</div></div>
<li>
<div class=ml_l></div>
<div class=ml_r><INPUT class=btn_submit tabIndex=4 type=submit value="登陆">
</div>
<div class=clearit></div>
</LI>
</UL>
</DIV>
<div class=main_bottom></div>
</FROM>




名字叫LoginC1的servlet
package com.helloworld;

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 LoginC1 extends HttpServlet {

/**
* Constructor of the object.
*/
public LoginC1() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
try
{
//中文乱码情况
response.setContentType("text/html; charset=gbk");
//接受用户和密码
String u=request.getParameter("username");
System.out.println(u);
String p=request.getParameter("passwd");
//验证
if(u.equals("root")&&p.equals("root"))
{
//合法
response.sendRedirect("Welcome");
}
else
{
response.sendRedirect("erro");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}


}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
this.doGet(request,response);

}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}


名叫welcome的servlet
package com.helloworld;

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 Welcome extends HttpServlet {

/**
* Constructor of the object.
*/
public Welcome() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
try
{
//中文乱码
response.setContentType("text/html;charset=gbk");
PrintWriter pw=response.getWriter();
//返回登陆界面
pw.println("<html>");
pw.println("<body>");
pw.println("<h1>Welcome</h1>");
pw.println("</body>");
pw.println("</html>");

}
catch(Exception ex)
{
ex.printStackTrace();
}

}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
this.doGet(request,response);
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}


最后是配置的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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_3_0.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>LoginC1</servlet-name>
<servlet-class>com.helloworld.LoginC1</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Welcome</servlet-name>
<servlet-class>com.helloworld.Welcome</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>LoginC1</servlet-name>
<url-pattern>/LoginC1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Welcome</servlet-name>
<url-pattern>/Welcome</url-pattern>
</servlet-mapping>

</web-app>



我是菜鸟,这些东西完全照书敲上去的,大家看看能不能帮我看看问题出在哪
...全文
122 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
低调小星 2014-06-08
  • 打赏
  • 举报
回复
引用 3 楼 u012724379 的回复:
form表单
谢谢啦 原来是我粗心打错了啊
-江沐风- 2014-06-08
  • 打赏
  • 举报
回复
form表单
低调小星 2014-06-08
  • 打赏
  • 举报
回复
引用 1 楼 u012618597 的回复:
你的表单包含着基本整个页面的内容看起来有点乱呀 你显示页面后 输入完毕点击登录是完全没有反应的吗 还是有错误显示的
可以打开页面不报错,但是点击登陆按钮没有反应 还有 刚才发现,我的login.jsp 里面有一个警告在第二行 说uknown tag (from) 百度了下没找到结果
易_xhao 2014-06-08
  • 打赏
  • 举报
回复
你的表单包含着基本整个页面的内容看起来有点乱呀 你显示页面后 输入完毕点击登录是完全没有反应的吗 还是有错误显示的

81,091

社区成员

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

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