Eclipse开发web项目

在Eclipese中添加Tomcat

window
preferences
server
Runtime Environment

进行Add Tomcat服务器,记得在server窗口中也要添加一下

新建web项目

  1. new 新建Dynamic Web project
  2. 在webcontent下面创建index.jsp
  3. 在浏览器中输入http://localhost:8080/Mystudy/index.jsp 进行访问项目
    WEB-INF无法通过浏览器直接访问,只能通过请求转发来访问

修改Eclipse中Tomcat的地址

在Eclipse中编辑html文件实时预览

右键单击html文件 选择open with web page editor

页面中form表单的action填写如下

在这里插入图片描述

编码问题

设置requset编码
request.setCharacterEncoding("utf-8");
或者
String name = new String(request.getParameter("username").getBytes("ISO8859-1"),"utf-8");

设置response编码
response.setContentType("text/html;charset=utf-8");

JDBC连接Mysql数据库

配置Struts2

struts2.5 版本的web.xml 写法

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
  id="WebApp_ID"
   version="3.1">
  <filter>

<filter-name>struts2</filter-name>

<filter-class>

  org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter

</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>
    
  </welcome-file-list>

</web-app>

struts.xml的写法

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 "http://struts.apache.org/dtds/struts-2.0.dtd" >
<struts>
	<package name="myPackage" extends="struts-default">
	<action name="hello">
		<result>/success.jsp</result>
	</action>
	</package>
</struts>

web.xml 配置

配置错误页面,将以下代码片段添加到<web-app>标签里

 <error-page>
  	<error-code>404</error-code>
  	<location>/error.jsp</location>
  </error-page>

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值