回 帖 发 新 帖 刷新版面

主题:用户登陆界面为什么无法运行?

<%--MyJsp.jsp--%>

<%@page language="java" contentType="text/html;charset=gb2312"%>

<html>
<head></head>
<body>
    <FORM name="login" method="POST">
    <INPUT type="text" name="name" />
    <INPUT type="password" name="password" />
    <INPUT type="Submit" name="button1" value="提交" />
    </FORM>
    
    <%--JSP部分--%>
    <%
    String name = request.getParameter("name");
    String password = request.getParameter("password");
    if( name.equals("killercat") && password.equals("123"))
    {
    %>
    <jsp:forward page="success.jsp">
        <jsp:param name = "user" value = "<%=name%>" />
    </jsp:forward>
    <%
    }else{
    %>
    <jsp:forward page="error.jsp">
        <jsp:param name="user" value="<%=name%>"/>
    </jsp:forward>
    <%}%>    

    
</body>
</html>



<%--error.jsp--%>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'error.jsp' starting page</title>
    

  </head>
  
  <body>
    不存在用户:<%=request.getParameter("user")%><br>
  </body>
</html>




<%--success.jsp--%>

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

  </head>
  
  <body>
    欢迎<%=request.getParameter("user")%>光临本网站<br>
  </body>
</html>

回复列表 (共2个回复)

沙发

在地址栏输入地址运行,很正常啊!
但如果刷新页面的话就出现异常:
description: The server encountered an internal error () that prevented it from fulfilling this request.

exception :
org.apache.jasper.JasperException
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause:
java.lang.NullPointerException
    org.apache.jsp.myjsp_jsp._jspService(myjsp_jsp.java:59)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

不知道是什么原因?

板凳

只要在form里面加上属性 action ="MyJsp.jsp"就可以了

我来回复

您尚未登录,请登录后再回复。点此登录或注册