struts2学习中遇到的问题1
来源:互联网 发布:java分布式开发详解 编辑:程序博客网 时间:2024/05/22 11:38
来源于java视频教程高级教程day37
struts2流程:
开发流程:
1 创建javaweb工程
2 找到开发Struts2应用需要使用到的jar文件.
3 创建jsp文件.
4 创建action文件
5 编写Struts2的配置文件
6 在web.xml中加入Struts2 MVC框架启动配置
1,2
3、jsp文件(test.jsp)
<%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%><%@ taglib uri="/struts-tags" prefix="s"%><html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body>访问路径:: <a href="${pageContext.request.contextPath}/helloWorldAction.action">helloWorld</a><br> <a href="${pageContext.request.contextPath}/helloWorldAction.action?username='bai'">ddddddd</a><br> 测试struts2 输出helloworld:<br> <a href="${pageContext.request.contextPath}/primer/helloWorldAction.action">helloWorld</a><br> 测试struts2 输出没有命名空间helloworld:<br> <a href="${pageContext.request.contextPath}/primer/primer/helloWorldAction.action">helloWorld</a><br> </body></html>
4 action文件(HelloWorldAction.java)
package cn.itcast.web.a_primer;import com.opensymphony.xwork2.Action;public class HelloWorldAction implements Action {private String username;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public HelloWorldAction(){System.out.println("这是HelloWorldAction的构造方法");} public String execute() throws Exception{ System.out.println(this.getUsername()+"欢迎访问hellowordaction"); return "success"; }}
5 struts.xml、
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN""http://struts.apache.org/dtds/struts-2.1.7.dtd"><struts><package name="primer" namespace="/" extends="struts-default"><action name="helloWorldAction" class="cn.itcast.web.a_primer.HelloWorldAction"><result name="success">/primer/success.jsp</result></action></package></struts>
6 web.xml、
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 这是struts2的核心过滤器,如果不使用该过滤器,不能使用struts2进行项目开发 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
遇到的一些问题:
myeclipse中启动tomcat报错
Unrecognized Windows Sockets error: 0: JVM_Bind 异常解决办法
到tomcat目录下的把conf文件夹下的server.xml文件中,找到
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
将该端口修改一下便可
<Connector port="8088" protocol="AJP/1.3" redirectPort="8443" />
org.apache.catalina.LifecycleException: Failed to start component
web.xml文件配置错了。
---------------------------------------------------------------------------------------------
${pageContext.request.contextPath}得到的是项目的相对路径, 如果为根目录那么就是空了,然后通过拦截器拦截bookAdmin然后找到相应的servlet进行处理。---------------------------------------------------------------------------------------------
There is no Action mapped for namespace / and action name helloWorldAction.检查拼写和文件名是否错误。
刚刚还能正常启动的tomcat又报端口被占的错。
win下查看被占用的端口 ”netstat -ano“ 查看全部被占的端口,原来我手动启动过tomcat服务(计算机管理服务中)
- struts2学习中遇到的问题1
- struts2学习中遇到的一些问题
- struts2学习中遇到的问题
- struts2 配置 学习 以及遇到的问题
- 学习struts2 遇到的一个问题
- 菜鸟学习Struts2遇到的问题
- struts2框架学习遇到的问题
- struts2 中使用 servlet遇到的问题
- struts2开发中经常遇到的问题
- struts2学习中遇到的错误
- struts2遇到的问题
- Struts2遇到的问题
- 学习中遇到的问题
- 学习中遇到的问题
- 自己学习Struts2过程中遇到的问题及解决办法(第一天)
- struts2学习遇到的小问题和小经验
- struts2+spring+hibernate使用中遇到的问题(转载)
- 自己搭建Struts2+Spring工程中遇到的问题
- android bluetooth开发基础(精典!)
- 黑帽SEO技术之各种站群技术篇
- 几何+点与线段的位置关系+二分(POJ2318)
- 让EasyUI的DataGrid直接内嵌的JSON对象,并重写formload方法
- android adb shell 命令大全
- struts2学习中遇到的问题1
- const,宏和内敛的使用
- 傅里叶分析之掐死教程(完整版)
- 【再次讨论】关于error lnk2019 无法解析的外部符号
- android去除标题栏和状态栏(全屏)
- JS取Map值
- 浅谈HTTP中Get与Post的区别
- MySQL数据表类型及文件结构
- Android软件开发之获取通讯录联系人信息