struts配置:<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="src-default">
<action name="LoginAction" class="default.LoginAction">
<result name=ERROR>/error.jsp</result>
<result name=SUCCESS>/success.jsp</result>
</action>
</package>
</struts> Action配置:import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {
private String user;
private String password;
public String getUser() {
return user;
}
public void setUser() {
this.user=user;
}
public String getPassword() {
return password;
}
public void setPassword() {
this.password=password;
}
public String execute() throws Exception {
if(getUser().equals("scott")&&getPassword().equals("123"))
return SUCCESS;
else return ERROR;
}
}web.xml配置:<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping></web-app>index.jsp配置:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title><ww:text name="loginTitle"/></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<ww:text name="loginTitle"/>
<hr>
<!-- 使用WebWork创建登录页面 -->
<ww:form method="post" action="success.jsp">
<!-- 生成登陆用的文本框 -->
<p>用户名:
<input type="text" name="user" lable="%{getText('user')}"/>
</p>
<!-- 生成登陆用的密码文本框 -->
<p>密 码 :
<input type="text" name="password" lable="%{getText('password')}"/>
</p>
<!-- 生成登录按钮 -->
<input type="submit" value="登录" />
</ww:form>
</body>
</html>error.jsp配置:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'error.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<p>用户名或者密码错误</p>
</body>
</html>success.jsp配置:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'success.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<p>欢迎你,scott登录成功!</p>
</body>
</html>
点击登陆后没有任何反应,求高手指点。
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="src-default">
<action name="LoginAction" class="default.LoginAction">
<result name=ERROR>/error.jsp</result>
<result name=SUCCESS>/success.jsp</result>
</action>
</package>
</struts> Action配置:import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {
private String user;
private String password;
public String getUser() {
return user;
}
public void setUser() {
this.user=user;
}
public String getPassword() {
return password;
}
public void setPassword() {
this.password=password;
}
public String execute() throws Exception {
if(getUser().equals("scott")&&getPassword().equals("123"))
return SUCCESS;
else return ERROR;
}
}web.xml配置:<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping></web-app>index.jsp配置:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title><ww:text name="loginTitle"/></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<ww:text name="loginTitle"/>
<hr>
<!-- 使用WebWork创建登录页面 -->
<ww:form method="post" action="success.jsp">
<!-- 生成登陆用的文本框 -->
<p>用户名:
<input type="text" name="user" lable="%{getText('user')}"/>
</p>
<!-- 生成登陆用的密码文本框 -->
<p>密 码 :
<input type="text" name="password" lable="%{getText('password')}"/>
</p>
<!-- 生成登录按钮 -->
<input type="submit" value="登录" />
</ww:form>
</body>
</html>error.jsp配置:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'error.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<p>用户名或者密码错误</p>
</body>
</html>success.jsp配置:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'success.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<p>欢迎你,scott登录成功!</p>
</body>
</html>
点击登陆后没有任何反应,求高手指点。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body bgcolor="pink">
<center>
<h4 align="center">用户登录界面</h4>
<hr>
<form action="loginCL.jsp" method="post" name="form1">
<tr>
<td> 姓 名:</td>
<td><input name="username" type="text" size="10"><br>
</td>
</tr>
<tr>
<td> 密 码:</td>
<td><input name="password" type="password" size="12"><br>
</td>
</tr>
<tr>
<td><input name="submit" type="submit" value="登录"
onClick="return checkIsNull()">
</td>
<td><input name="reset" type="reset" value="重置"><br>
</td>
</tr>
</center>
</form>
//javaScript脚本 用来判断是否输入为空
<script type="text/javascript">
function checkIsNull() {
if(form1.username.value==""){
window.alert("请输入用户名");
return false;
form1.username.focus();
}
if(form1.password.value==""){
window.alert("您还未输入密码");
return false;
form1.password.focus();
}
return ture;
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
try { //接受用户名和密码 String name = request.getParameter("username");
String passw = request.getParameter("password");
if (name.equals("您想要判断的用户名")) {
//说明用户存在
if (passw.equals("你想要判断的密码")) {
//合法,就跳转到成功页面
response.sendRedirect("welcome.jsp?user=" + name);
} else {
//不合法,就跳转回登录页面
response.sendRedirect("login.jsp?error=1");
}
} else {
response.sendRedirect("login.jsp?error=2");
} } catch (Exception e) {
e.printStackTrace();
}
%>
</body>
</html>
问题在于:
1 用了ww命名空间,未导入taglib
2 form Action直接指向了success.jsp,没有指向LoginAction.action
index.jsp有问题,其他还好。
问题在于:
1 用了ww命名空间,未导入taglib
2 form Action直接指向了success.jsp,没有指向LoginAction.action
那高手帮看下怎么改呢
感觉太乱了,
首先说说的你的struts的配置文件:<struts>
<package name="default" extends="src-default">
<action name="LoginAction" class="default.LoginAction">
<result name=ERROR>/error.jsp</result>
<result name=SUCCESS>/success.jsp</result>
</action>
</package>
</struts> 写程序的时候,最好分层,每层用不同的包名。
比如在com.test.action包下写Action类LoginAction,
配置如下:<action name="LoginAction" class="default.LoginAction">
<result name="error">/error.jsp</result>
<result name="success">/success.jsp</result>
</action>
然后是你的index页面:
没引进标签,在<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>下面加上:
<%@taglib prefix="ww" uri="webwork"%>
其次<ww:form method="post" action="success.jsp">action的值应该是在sturts中配置的action的名字LoginAction
<ww:form method="post" action="LoginAction">
<result name="success">/success.jsp</result>
这个只改了,那么LoginAction里面execute()的返回值也要改吧。
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="src-default">
<action name="LoginAction" class="default.LoginAction">
<result name=ERROR>/error.jsp</result>
<result name=SUCCESS>/success.jsp</result>
</action>
</package>
</struts> Action配置:import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {
private String user;
private String password;
public String getUser() {
return user;
}
public void setUser() {
this.user=user;
}
public String getPassword() {
return password;
}
public void setPassword() {
this.password=password;
}
public String execute() throws Exception {
if(getUser().equals("scott")&&getPassword().equals("123"))
return SUCCESS;
else return ERROR;
}
}web.xml配置:<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping></web-app>index.jsp配置:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title><ww:text name="loginTitle"/></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<from>
<p>用户名:
<input type="text" name="user" />
</p>
<!-- 生成登陆用的密码文本框 -->
<p>密 码 :
<input type="text" name="password" />
</p>
<!-- 生成登录按钮 -->
<input type="submit" value="登录" />
</from>
</body>
</html>这样是可以实现的!虽然改变了你的程序设计,但是可以实现相同的功能!
希望能成功!祝你好运!
2011-3-23 13:10:56 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_24\bin;D:\Tomcat\apache-tomcat-6.0.32\bin
2011-3-23 13:10:56 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2011-3-23 13:10:56 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 511 ms
2011-3-23 13:10:56 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2011-3-23 13:10:56 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.32
2011-3-23 13:10:56 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor host-manager.xml
2011-3-23 13:10:56 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor manager.xml
2011-3-23 13:10:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory docs
2011-3-23 13:10:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory examples
2011-3-23 13:10:57 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2011-3-23 13:10:57 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2011-3-23 13:10:57 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory mlams
2011-3-23 13:10:57 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
2011-3-23 13:10:57 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory Test
2011-3-23 13:10:57 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2011-3-23 13:10:58 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2011-3-23 13:10:58 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2011-3-23 13:10:59 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: Unable to find parent packages src-default
2011-3-23 13:10:59 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2011-3-23 13:10:59 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2011-3-23 13:10:59 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/31 config=null
2011-3-23 13:10:59 org.apache.catalina.startup.Catalina start
信息: Server startup in 2752 ms
2011-3-23 13:11:04 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /index.jsp(2,35) File "/webwork" not found
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:161)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:386)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:450)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1397)
at org.apache.jasper.compiler.Parser.parse(Parser.java:130)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:185)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:326)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)