<span style="font-family:Microsoft YaHei;font-size:18px;">简单地使用struts搭了一个小框架,有bug。问题应该是在struts-xml的配置上。</span><p><span style="font-family:Microsoft YaHei;font-size:18px;">代码如下:</span>
<span style="font-family:Comic Sans MS;font-size:18px;"><!DOCTYPE html>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- <script src="../ku/jquery.min.js"></script>
<script src="../ku/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="../ku/css/bootstrap.min.css"> -->
<!-- 不知道为什么直接引用电脑的竟然不行 -->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet"
href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<title>登陆界面</title>
</head>
<body>
<div class="container">
<div class="col-md-12"> </div>
<div class="col-md-12"> </div>
<form class="form-horizontal col-md-offset-3" action="/LogonAction">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="inputText3" name = "user"
placeholder="你的名字">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">密码</label>
<div class="col-sm-3">
<input type="password" class="form-control" id="inputPassword3"
placeholder="密码" name = "password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label> <input type="checkbox"> 记住我</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">登陆</button>
</div>
</div>
</form>
<!-- <form role="form">
<div class="form-group">
<label for="exampleInputEmail1">用户名</label>
<input
type="email" class="form-control" id="exampleInputEmail1"
placeholder="用户名">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label> <input
type="password" class="form-control" id="exampleInputPassword1"
placeholder="Password">
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label> <input type="file"
id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="checkbox">
<label> <input type="checkbox"> Check me out
</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form> -->
</div>
</body>
</html</span></p>
<span style="font-family:Comic Sans MS;font-size:18px;">package smartstruts;
import org.apache.struts.action.ActionForm;
public class UserForm extends ActionForm {
/**
*
*/
private static final long serialVersionUID = -771221078472143400L;
private String user;
private String password;
public String getUserId() {
return user;
}
public void setUserId(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
</span>
<span style="font-family:Comic Sans MS;font-size:18px;">package smartstruts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LogonAction extends Action {
/* (非 Javadoc)
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO 自动生成的方法存根
UserForm loginForm = (UserForm) form;
if("wom".equals(loginForm.getUserId())&&"123".equals(loginForm.getPassword())) {
return mapping.findForward("success");
}
return mapping.findForward("fail");
}
}
</span>
<span style="font-family:Comic Sans MS;font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-comfig>
<form-beans>
<form-bean name="userForm" type="smartstruts.UserForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/LogonAction" type="smartstruts.LogonAction" name="userFrom" scope="request">
<forward name="success" path="/ok.jsp"/>
<forward name="fail" path="/fail.jsp"/>
</action>
</action-mappings>
</struts-comfig></span>
回去继续看看,怎么回事?