首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

新人初学,卡在起点~Jsp的小疑点

2013-09-11 
新人初学,卡在起点~Jsp的小问题我是刚刚入手的JSP,按照教材编写简单的Bean测试,主要通过对“用户名”、“密码”

新人初学,卡在起点~Jsp的小问题
我是刚刚入手的JSP,按照教材编写简单的Bean测试,主要通过对“用户名”、“密码”和“年龄”的设置和查询练习对Bean的操作,却遇到了很大的问题,希望大家不吝赐教。
使用JDK   6+Tomcat   5.0.28+NetBeans   5.5进行开发。
源代码如下:

/**
TestBean.java
*/

package   com.jspdev.ch3;

public   class   TestBean
{
public   String   userName;
public   String   password;
public   int   age;  

public   void   setUserName(String   name)
{
this.userName=name;
}
public   void   setPassword(String   passwordTemp)

{
this.password=passwordTemp;
}
public   String     getUserName()
{
return   this.userName;
}
public   String   getPassword()
{
return   password;
}
public   int   getAge()
{
return   this.age;
}
public   void   setAge(int   ageTemp)
{
this.age=ageTemp;
}
}

/**
TestBean.java   结束
*/


/**
register.jsp
*/

<%@   page   contentType= "text/html;charset=gb2312 "%>  
<jsp:useBean   id= "user "   scope= "page "   class= "com.jspdev.ch3.TestBean "/>
<jsp:setProperty   name= "user "   property= "* "/>
<html>  
<body>  
注册成功: <br>
<hr>
使用bean属性方法: <br>
用户名: <%=user.getUserName()   %> <br>
密码: <%=user.getPassword()   %> <br>
年龄: <%=user.getAge()   %> <br>
<hr>
使用getProperty: <br>
用户名: <jsp:getProperty   name= "user "   property= "userName "/> <br>
密码: <jsp:getProperty   name= "user "   property= "password "/> <br>
年龄: <jsp:getProperty   name= "user "   property= "age "/> <br>
</body>  
</html>  

/**
register.jsp   结束
*/


/**
regiester.html
*/

<html>
<body>
用户信息注册: <br> <hr>
<form   method= "get "   action= "register.jsp ">
<table>
<tr> <td> 姓名: <input   name= "userName "   type= "text "> </td> </tr>
<tr> <td> 密码: <input   name= "password "   type= "password "> </td> </tr>
<tr> <td> 年龄: <input   name= "age "   type= "text "> </td> </tr>
<tr> <td> <input   type=submit   value= "submit "> </td> </tr>
</table>
</form>
</body>
</html>

/**
regiester.html   结束
*/

但是无论直接通过IE运行还是NetBeans编译,register.jsp始终通过不过编译。
在NetBeans中报错:
compile-single-jsp:
Duplicated   project   name   in   import.   Project   Register-impl   defined   first   in   C:\Documents   and   Settings\Java\Register\nbproject\ant-deploy.xml   and   again   in   C:\Documents   and   Settings\Java\Register\nbproject\build-impl.xml
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
org.apache.jasper.JasperException:     The   value   for   the   useBean   class   attribute   com.jspdev.ch3.TestBean   is   invalid.


C:/Documents   and   Settings/Java/Register/build/web/register.jsp(2,0)
C:\Documents   and   Settings\Java\Register\nbproject\build-impl.xml:372:   The   following   error   occurred   while   executing   this   line:
C:\Documents   and   Settings\Java\Register\nbproject\build-impl.xml:353:   Java   returned:   1
生成失败(总时间:1   秒)

如果在IE中,运行regiester.html,提交完表单,就会报错:
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:   /register.jsp(2,0)   The   value   for   the   useBean   class   attribute   com.jspdev.ch3.TestBean   is   invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)


root   cause  

org.apache.jasper.JasperException:   /register.jsp(2,0)   The   value   for   the   useBean   class   attribute   com.jspdev.ch3.TestBean   is   invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3305)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)


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

1.问题出现在什么地方呢?我直接使用光盘上的范例程序也还是会出现这样的情况。为什么?有谁可以告诉我么?

2.另外还有一个问题,我根据书上的范例程序,把TestBean.java放进了WEB-INF/classes这个文件夹里面,可是从代码上看,好像放在什么文件夹里面没有什么关系啊,不过我不能验证,因为通不过编译,都没有办法调用TestBean.java。

3.在TestBean.java中,“package   com.jspdev.ch3”这一句是打包对么?这句有什么作用?难道不是对应的相应文件夹么?

------解决方案--------------------


原因是你的TestBean.java没有编译成.class文件
编译后把TestBean.class放到WEB-INF/classes/com/jspdev/ch3下
[解决办法]
package com.jspdev.ch3
这句话的意思是,包名是“com.jspdev.ch3”
所以你工程里的包名也必须是这个,否则会找不到包,而出错的。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行