SSH(三)创建包和第一个页面

在ssh web项目src下一次创建

com.ssh/

  .action

  .dao

  .entity

  .service

四个包,example:

在entity包下创建class,name: product →finish

package com.ssh.entity;
/**
 * @author:图图
 * @date : 2017-6-12 下午08:54:54
 * 商品属性
 */ 
public class product {
	private Integer pid;
	private String pname;
	private Double price;
	public Integer getPid() {
		return pid;
	}
	public void setPid(Integer pid) {
		this.pid = pid;
	}
	public String getPname() {
		return pname;
	}
	public void setPname(String pname) {
		this.pname = pname;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	
}

在webroot下create我们的第一个页面addproduct.jsp

注意:Struts2标签库的引入

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!-- struts2 标签库 -->
<%@taglib uri ="/struts-tags" prefix="s" %>
<%
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 'addproduct.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>
    <h1>商品保存</h1>
    <!-- theme="simple" 放弃使用struts form 样式  -->
    <s:form action="" method="post" namespace="/" theme="simple">
    	<table border="1" width="400">
    		<tr>
    			<td>商品名称:</td>
    			<td><s:textfield name="pname"/></td>
    		</tr>
    		<tr>
    			<td>商品价格:</td>
    			<td><s:textfield name="price"/></td>
    		</tr>
    		<tr>
    			<!-- colspan: 合并单元格-->
    			<td align="center" colspan="2"><input type="submit" value="添加"> </td>
    		</tr>
    	</table>
    </s:form>
  </body>
</html>

tomcat添加项目ssh

根据自己的tomcat端口访问:

http://localhost:8080/ssh/addproduct.jsp

页面show:

 

原文地址:https://www.cnblogs.com/ckxlovejava/p/6995651.html