我是没接触过这个东西的,昨天跟今天有看,然后现在这样子我不知道到底是什么情况,到底这一部分做完没,接下来该怎么做,愿意说下的就说下呗
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE struts PUBLIC 3 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 4 "http://struts.apache.org/dtds/struts-2.0.dtd"> 5 <struts> 6 <package name="default" extends="struts-default"> 7 <action name="log" class="per.zxl.TestAction" method="msg"> 8 <result>/login.jsp</result> 9 </action> 10 </package> 11 </struts>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 3 <display-name>struts</display-name> 4 <welcome-file-list> 5 <welcome-file>index.jsp</welcome-file> 6 </welcome-file-list> 7 <filter> 8 <filter-name>struts2</filter-name> 9 <filter-class> 10 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 11 </filter-class> 12 </filter> 13 <filter-mapping> 14 <filter-name>struts2</filter-name> 15 <url-pattern>/*</url-pattern> 16 </filter-mapping> 17 </web-app>
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <form action="log" method="post"> 11 <table align="center"> 12 <tr> 13 <td>账号:</td> 14 <td><input type="text" name="username"></td> 15 </tr> 16 <tr> 17 <td>密码:</td> 18 <td><input type="text" name="username"></td> 19 </tr> 20 <tr> 21 <td> 22 <button type="submit" value="mitbit">登录</button> 23 </td> 24 </tr> 25 </table> 26 </form> 27 </body> 28 </html>
1 package per.zxl; 2 3 import com.opensymphony.xwork2.ActionSupport; 4 5 public class TestAction extends ActionSupport{ 6 7 private String username; 8 private String password; 9 //get set 10 public String getUsername() { 11 return username; 12 } 13 public void setUsername(String username) { 14 this.username = username; 15 } 16 public String getPassword() { 17 return password; 18 } 19 public void setPassword(String password) { 20 this.password = password; 21 } 22 23 24 25 public String msg(){ 26 return SUCCESS; 27 } 28 29 30 }
1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 pageEncoding="ISO-8859-1"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 is login 11 </body> 12 </html>
其中,login.jsp我先前用来测试的,现在想做的是,当输入用户名或者密码后,判断它是否正确,正确就跳转到login.jsp,错误就跳转到新建页面error.jsp中,但我现在不晓得该怎么做了
顺带问下,如果加上jdbc,该怎么做?
struts.xml中result 可以配置多个的:
<result name="success">/login</result> <result name="error">/error.jsp</result>
在msg方法中判断账号和密码,正确返回"success",错误返回"error"
是这样么.判断实体的username.equals(放表单中的username)?