搭建Struts框架

搭建Struts框架

新建项目->
	点击项目右键->
		MyEclipse->
			Add Struts Capabilities选择Struts1.2
				->Finish

简单Struts1案例

index.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


	
		
		index.jsp
	
	
		
账号
密码
web.xml


	
		action
		
			org.apache.struts.action.ActionServlet
		
		
			config
			/WEB-INF/struts-config.xml
		
		
			debug
			3
		
		
			detail
			3
		
		0
	
	
		action
		*.do
	
	
		index.jsp
	
struts-config.xml




	
		
		
		
			
			
			
		
	
	
	
LoginAction.java
package com.itlwc.action;

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 LoginAction extends Action {
	// ActionMapping对象里面装载的是struts-config.xml文件中的配置信息
	// ActionForward类:封装了servlet中的跳转命令
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		if ("lwc".equals(username)&&"123".equals(password))
			return mapping.findForward("success");
		else
			return mapping.findForward("unsuccess");
	}
}
success.jsp
<%@ page language="java" pageEncoding="UTF-8"%>


	
		success.jsp
	
	
		登陆成功
	
unsuccess.jsp
<%@ page language="java" pageEncoding="UTF-8"%>


	
		unsuccess.jsp
	
	
		登陆失败
	

你可能感兴趣的:(Java框架之Struts1)