I am beginner in JSP and trying to do simple jsp page. ı want to set my class fields name and surname and print on the page. My class :
package org.mypackage.person;
/**
*
* @author cemalinanc
*/
public class Person {
private String name;
private String surname;
Person()
{
name = null;
surname = null;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the surname
*/
public String getSurname() {
return surname;
}
/**
* @param surname the surname to set
*/
public void setSurname(String surname) {
this.surname = surname;
}
}
页: 1 jsp与:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<form name="input form" action="response.jsp">
Name:
<input type="text" name="name" value="" />
Surname:
<input type="text" name="surname" value="" />
<input type="submit" value="Ok" />
</form>
</body>
</html>
我的答复。 jsp page
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean id="mybean" scope="session" class="org.mypackage.person.Person" />
<jsp:setProperty name="mybean" property="name" />
<h1>Hello, <jsp:getProperty name="mybean" property="name" />!</h1>
</body>
</html>
I just want to set two fields in the class and print to screen both of them but i could not. Later i tried to print just name field but again could not. I take an error like:
The server encountered an internal error () that prevented it from fulfilling this request. org.apache.jasper.JasperException: /response.jsp (line: 15, column: 8) The value for the useBean class attribute org.mypackage.person.Person is invalid.
What is the problem with this?
如果你能给我一个想法,那将不胜感激。 非常感谢您的帮助。