0

An error occurred at line: 21 in the jsp file: /Test.jsp UserNameCheck cannot be resolved

Above is the error I receive. The .jsp file I am using is:

<%@page import="webtest.*"%>
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>


<%  
String username = request.getParameter("username");
    String password = request.getParameter("password");%>
<h1>Hey <%=UserNameCheck.CheckLogin(username,password)%></h1>
</body>
</html>

and the Class code is

package webtest;
public class UserNameCheck{
    public static String CheckLogin(String X,String Y){
    return X;
}
}

I am pretty sure I am overlooking something incredibly stupid right now. Or the approach I am taking is not possible.
I have crash coursed in java for my company over the past 3 or 4 weeks. My learning has been incredibly unstructured, so don't assume anything.

What I know. The username and password variables give accurate results. If I changed the code to

<h1> hey <%=username%></h1>

I receive what I want.

Matt
  • 265
  • 2
  • 3
  • 10
  • 3
    To make it work: Move the validation in the scriplet just below the line where you set the password variable. Assign the result in another variable, let's say `String x`, and then do `Hey <%= x %>` inside the `

    ` and make sure there is no other code that can throw any exception in your JSP page. A good advice: don't use scriptlets, its a bad way to program in JSP, read [How to avoid Java Code in JSP-Files?](http://stackoverflow.com/a/3180202/1065197) to have a better idea to solve these problems.

    – Luiggi Mendoza Jul 06 '12 at 15:14
  • don't use scriptlets use jstl tags – NimChimpsky Jul 06 '12 at 15:39
  • @Matt - Ensure that the `UserNameCheck.class` must be located at `WEB-INF/classes/webtest/`. (and restart the context/webserver) – KV Prajapati Jul 07 '12 at 06:56
  • @AVD I am using an Eclipse Tomcat Project. The class is located at WEB-INF/src/webtest. I have not looked at this problem since the weekend, but it still persists unfoturnately, – Matt Jul 09 '12 at 14:02
  • @Matt - Clean and rebuild your project or create another component/class and test it. – KV Prajapati Jul 09 '12 at 14:30
  • So thanks for everyone that intended to help. There was so much wrong with the project/workspace I just created a new workspace. Ran everything exactly the same and it worked out just fine. I have spent way to much time on this though. Thanks AVD for suggesting I rebuild the project, I guess I took that advice sort of. – Matt Jul 09 '12 at 18:44

1 Answers1

-1

You can use JSP declaration instead:

  <%! 
      String CheckLogin(String X,String Y){
         return X;
      }
  %>

And then call this method:

<h1>Hey <%= CheckLogin(username,password) %></h1>