I am new in this site and as a programmer I consider myself to be beginner/intermediate level. I am new in java and have to work with JSP for an University course. I want to know what is wrong with this code because I am receiving this error:
我是这个网站的新手,作为程序员,我认为自己是初级/中级水平。我是java新手,必须使用JSP进行大学课程。我想知道这段代码有什么问题,因为我收到了这个错误:
the requested resource is not available.
请求的资源不可用。
Here is all my code:
这是我的所有代码:
session.jsp
<html>
<body>
<form method = Post action = “receiveName.jsp”>
please enter your name: <input type = "text" name = "myname" size = 20></br>
<input type = "submit"><input type = "clear">
</form>
</body>
</html>
receiveName.jsp
<jsp:useBean id="bean" class="mynames.Names" scope="session"/>
<jsp:setProperty name="bean" property="myNames" param="myname"/>
<% String name = bean.getMyNames();
session.setAttribute(“user”, name);
%>
<html>
<body>
<a href = “showname.jsp”>move to next page</a>
</body>
</html>
showName.jsp
<html>
<body>
Hello <% = session.getAttribute(“user”)%>
</body>
</html>
Names.java
package mynames;
public class Names{
private String myNames;
public Names(){
}
public void setMyNames(String name){
myNames = name;
}
public String getMyNames(){
return myNames;
}
}
I don't understand how to implement the concept of bean very well and if I run the receiveName.jsp alone the following report appears:
我不明白如何很好地实现bean的概念,如果我单独运行receiveName.jsp,则会出现以下报告:
org.apache.jasper.JasperException: /EjemploProfesor/Class/receiveName.jsp (line: 1, column: 1) The value for the useBean class attribute mynames.Names is invalid.
Every input from you will be very appreciated. By the way, I am not using an IDE, just Sublime Text 2 running in Ubuntu and as server Apache Tomcat 8.0.21
非常感谢您的每一个意见。顺便说一句,我没有使用IDE,只使用在Ubuntu中运行的Sublime Text 2和作为服务器的Apache Tomcat 8.0.21
2 个解决方案
#1
You will have to change the “
to "
in your whole code.
您必须在整个代码中更改“to”。
For eg:
<form method = Post action = “receiveName.jsp”>
has to be changed to
必须改为
<form method = Post action = "receiveName.jsp">
Similarly, change the below given lines
同样,更改以下给定的行
session.setAttribute(“user”, name);
<a href = “showname.jsp”>
Hello <% = session.getAttribute(“user”)%>
to
session.setAttribute("user", name);
<a href = "showname.jsp">
Hello <% = session.getAttribute("user")%>
respectively
#2
You need to import the class Names
in your receiveName.jsp
您需要在receiveName.jsp中导入类名
<%@page import="mynames.Names"%>
#1
You will have to change the “
to "
in your whole code.
您必须在整个代码中更改“to”。
For eg:
<form method = Post action = “receiveName.jsp”>
has to be changed to
必须改为
<form method = Post action = "receiveName.jsp">
Similarly, change the below given lines
同样,更改以下给定的行
session.setAttribute(“user”, name);
<a href = “showname.jsp”>
Hello <% = session.getAttribute(“user”)%>
to
session.setAttribute("user", name);
<a href = "showname.jsp">
Hello <% = session.getAttribute("user")%>
respectively
#2
You need to import the class Names
in your receiveName.jsp
您需要在receiveName.jsp中导入类名
<%@page import="mynames.Names"%>