急!!!我是个struts的初学者,一天一个程序都没调试出来,急死我了.请大家帮帮忙!大恩不言谢!
我是struts初学者,做了个登录,可怎么也运行不了。以下是目录结构:
TryStruts
| src
| app
| RegisterForm.java
| RegisterAction.java
| TryStrus
| WEB-INF
|success.html
|failure.html
|struts-config.xml
|struts-html.tld
|web.xml
| Register.jsp
开发工具:MyEclipse, Tomcat5.5, jdk6.0
Register.jsp源代码如下:
<%@ page language= "java " import= "java.util.* " pageEncoding= "gbk "%>
<%@ taglib uri= "WEB-INF/struts-html.tld " prefix= "html "%>
<%
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 action= "/Register.do ">
rUsername <html:text property= "username "/> <br>
enter password <html:password property= "password1 "/> <br>
re-enter password <html:password property= "password1 "/> <br>
<html:submit value= "Register "/>
</html:form>
Struts-config.xml代码如下:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN " "http://struts.apache.org/dtds/struts-config_1_2.dtd ">
<struts-config>
<data-sources />
<form-beans>
<form-bean name= "registerForm " type= "app.RegisterForm "/>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path= "/Register " type= "app.RegisterForm " name= "registerForm ">
<forward name= "success " path= "/success.html "/>
<forward name= "failure " path= "/failure.html "/>
</action>
</action-mappings>
<message-resources parameter= "ly.ApplicationResources " />
</struts-config>
RegisterAction.java代码如下:
package app;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.io.*;
public class RegisterAction extends Action {
public ActionForward perform (ActionMapping mapping,ActionForm form,HttpServlet request,HttpServlet response) {
RegisterForm rf = (RegisterForm)form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
if(password1.equals(password2)) {
return mapping.findForward( "success ");
}
return mapping.findForward( "failure ");
}
}
RegisterForm.java代码如下:
package app;
import org.apache.struts.action.*;
public class RegisterForm extends ActionForm {
String username;
String password1;
String password2;
public RegisterForm (String username,String password1,String password2) {
this.username = username;
this.password1 = password1;
this.password2 = password2;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword1(String password1) {
this.password1 = password1;
}
public void setPassword2(String password2) {
this.password2 = password2;
}
public String getUsername() {
return this.username;
}
public String getPassword1() {
return this.password1;
}
public String getPassword2() {
return this.password2;
}
}
其中web.xml中部分代码:
。。。
<servlet-mapping>
<servlet-name> action </servlet-name>
<url-pattern> *.do </url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file> Register.jsp </welcome-file>
</welcome-file-list>
。。。
我在浏览器中输入: http://localhost:8080/TryStruts/
试了好几遍,出错如下:
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: Exception in JSP: /Register.jsp:10
7:
8: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
9:
10: <html:form action= "/Register.do ">
11: rUsername <html:text property= "username "/> <br>
12: enter password <html:password property= "password1 "/> <br>
13: re-enter password <html:password property= "password1 "/> <br>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: Cannot retrieve mapping for action /Register
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.Register_jsp._jspService(Register_jsp.java:88)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /Register
org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:810)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506)
org.apache.jsp.Register_jsp._jspx_meth_html_005fform_005f0(Register_jsp.java:104)
org.apache.jsp.Register_jsp._jspService(Register_jsp.java:78)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
________________________________________
Apache Tomcat/5.5.23
[解决办法]
你的JSP页面的错误
提示告诉你了 acation= " "里的do去掉 因为你在xml里的PATH属性不一样 我感觉是这样 好久没用struts 不过错误提示告诉你很详细了
[解决办法]
是这样的,在你的配置文件里写了:
<action path= "/Register " type= "app.RegisterForm " name= "registerForm ">
表示配置了一个action的映射路径为/Register,而你在JSP里写的路径是/Register.do,这样不匹配所以出错了。
[解决办法]
楼主的配置是没有问题的,请你确认一下WEB-INF目录下有没有生成的classes文件夹,在其中有没有相应的.class文件?
[解决办法]
Struts-config.xml中 <action path= "/Register " type= "app.RegisterAction " name= "registerForm ">
你写成 type= "app.RegisterForm "
[解决办法]
<action path= "/Register " type= "app.RegisterForm " name= "registerForm ">
这句有问题, type指的是action类的全名,不是form的全名,你好好看看例子吧
[解决办法]
你的程序要放到服务起目录中才能运行,myeclipse的deploy是把的程序放到服务器下,不用手动的配置拉
我的异常网推荐解决方案:程序员的一天,http://www.myexception.cn/other/1391144.html
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html