a testcase writen by watij base on java can not be used in JSP

D

davy

when i run a jsp web after starting tomcat, where the code is
<% gdpTest n2 = new gdpTest();
n2.testGunDP();
%>
where gdpTest is one class extends testCase in Junit,
and i have imported the class gdpTest in JSP web, when i open the jsp
web, the information in the web is
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 20 in the jsp file: /gdptest.jsp
Generated servlet error:
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina
\localhost\myTest\org\apache\jsp\gdptest_jsp.java:87: ÎÞ·¨·ÃÎÊ
junit.framework.TestCase
ÕÒ²»µ½Îļþ junit\framework\TestCase.class
gdpTest n2 = new gdpTest();
^
1 ´íÎó




org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:
84)

org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:
332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:
511)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
295)
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)


note The full stack trace of the root cause is available in the Apache
Tomcat/5.0.28 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28

well, i think i have configed the right classpath in my computer,
because when i import another project class and use its method, the
jsp web's information is right without no mistakes
so i have one question, jsp can not use project extends junit?

thanks
 
S

stefanomnn

HI,
whats' the pakage of that class?
be sure you imported it with import directive.

Stefano
 
L

Lew

davy said:
when i run a jsp web after starting tomcat, where the code is
<% gdpTest n2 = new gdpTest();
n2.testGunDP();
%>
where gdpTest is one class extends testCase in Junit,
and i have imported the class gdpTest in JSP web, when i open the jsp
web, the information in the web is
HTTP Status 500 -

You do not provide a simple, self-contained compilable (correct) example,
SSCCE, so it is not really possible for us to speak to your difficulty with
any assurance.

For example, you say you import the "gdpTest" class but do not show the import
statement(s). If they were flawed, you'd have trouble but we couldn't see it.

Another thing not shown is the code for the constructor - perhaps there is no
default constructor, or there is some other mistake that makes the "new" not
compile. Or perhaps there isn't.

Also, this has no bearing on your difficulty perhaps, but class names by
convention (only) should start with upper-case letters. Check out the Sun
coding conventions.

Have you examined the generated .java for the JSP? Is it what you expect
around the point of your scriptlet?

This is part of why Marty Hall and many other pundits strongly recommend not
to use scriptlet in JSPs. Stick with tag libraries, like the JSTL and JSF,
and push the logic out of the JSP. Java classes are easier to debug, and the
JSP is easier to maintain when it it narrowly focused on view concerns.
 
D

davy

thanks for your answers

this is the code of gdpTest,java, which has imported the watij (a
latest plugin to open IE automatically)

package watijTest;



import watij.runtime.ie.IE;
import junit.framework.TestCase;
import static watij.finders.SymbolFactory.*;


public class gdpTest extends TestCase {

public void testLogin(IE paIe,String unm, String pwd) throws
Exception{

paIe.start("http://test.com/");
paIe.maximize();
paIe.textField(name, "username").set(unm);
paIe.textField(name, "password").set(pwd);
paIe.button(name, "ok").click();

}

// 1 12
public void testHighGDP() throws Exception {

//
production n1 = new production();
n1.setAllElements("patient123", "12346", "1234567890210",
"456767890210", 6,
"http://www.12361890210.com");

final IE ie = new IE();

//
this.testLogin(ie,"user", "pwd");



//
new Thread(new Runnable() {
public void run() {
try {
ie.sendKeys("Microsoft Internet Explorer", " ");
} catch (Exception e) {
}
}
}).start();
ie.frame(1).link(1).click();




System.out.println(ie.frame(1).table(3).table(1).table(1).cell(1)
.text().toString());
// 10515204 1200

}
}

and production is another class

the JSP is as below

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

<jsp:directive.page import="watijTest.production"/>

<jsp:directive.page import="watijTest.gdpTest"/>
<jsp:directive.page import="junit.*"/>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()
+":"+request.getServerPort()+path+"/";
%>

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

<form method=post action="3.jsp?pass=11">

<%
gdpTest n2 = new gdpTest();
n2.testGunDP();
//n1.ttttt();

%>
<input type=submit value=submit>

</form>

</html>

and the web information is also the above: they can not find the
junit.* but i have import it to my project

thanks.
 
L

Lew

davy said:
thanks for your answers

this is the code of gdpTest,java, which has imported the watij (a
latest plugin to open IE automatically)

package watijTest;

import watij.runtime.ie.IE;
import junit.framework.TestCase;
import static watij.finders.SymbolFactory.*;


public class gdpTest extends TestCase {

public void testLogin(IE paIe,String unm, String pwd) throws
Exception{

paIe.start("http://test.com/");
paIe.maximize();
paIe.textField(name, "username").set(unm);
paIe.textField(name, "password").set(pwd);
paIe.button(name, "ok").click();

}

// 1 12
public void testHighGDP() throws Exception {

//
production n1 = new production();
n1.setAllElements("patient123", "12346", "1234567890210",
"456767890210", 6,
"http://www.12361890210.com");

final IE ie = new IE();

//
this.testLogin(ie,"user", "pwd");



//
new Thread(new Runnable() {
public void run() {
try {
ie.sendKeys("Microsoft Internet Explorer", " ");
} catch (Exception e) {
}
}
}).start();
ie.frame(1).link(1).click();




System.out.println(ie.frame(1).table(3).table(1).table(1).cell(1)
.text().toString());
// 10515204 1200

}
}

and production is another class

the JSP is as below

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

<jsp:directive.page import="watijTest.production"/>

<jsp:directive.page import="watijTest.gdpTest"/>
<jsp:directive.page import="junit.*"/>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()
+":"+request.getServerPort()+path+"/";
%>

Why is this scriptlet here? It doesn't do useful work, and scriptlet really
doesn't belong in a JSP if you can help it, anyway.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<form method=post action="3.jsp?pass=11">

<%
gdpTest n2 = new gdpTest();
n2.testGunDP();

According to the code you provide, there is no such symbol as "testGunDP()".
//n1.ttttt();

%>
<input type=submit value=submit>

Where are the quote marks for the attribute values? The close tag?
(Not the cause of your problem, though)
</form>

</html>

and the web information is also the above: they can not find the
junit.* but i have import it to my project

Who is "they"? What is the (exact) error message?

My guess is that this "JSP" crashes on the call to the nonexistent
"n2.testGunDP()".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top