maven项目构建struts2框架项目遇到的org.apache.jasper.JasperException: Unable to compile class for JSP:

创建maven工程时,并加入struts2框架,解析jsp页面的问题的时候,会出现如下异常

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

An error occurred at line: 22 in the generated java file
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

通过查询资料
有博友写的文章 标题 unable to compile class for JSP(不能编译class)

点击打开链接

文中提到结论:1、我的工程里的servlet.jar、jsp-servlet.jar的版本比较低与tomcat6.0相比。

                            2、tomcat的下面的lib里面不能与工程里面的jar相同(如果部署到tomcat上)。

                            3、把工程里面的两个jar包删除了,就解决了。

一直没有弄明白,直到查看了http

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
搭建Struts2项目需要按照以下步骤进行: 1. 创建Maven项目 在命令行中执行以下命令,创建一个Maven项目: ``` mvn archetype:generate -DgroupId=com.example -DartifactId=my-struts2-app -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false ``` 其中,`-DgroupId`表示项目的groupId,`-DartifactId`表示项目的artifactId,`-DarchetypeArtifactId`表示使用的模板,这里使用的是maven-archetype-webapp。 2. 添加Struts2依赖 在`pom.xml`文件中添加Struts2依赖: ```xml <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.5.26</version> </dependency> ``` 3. 创建Struts2配置文件 在`src/main/resources`目录下创建`struts.xml`文件,配置Struts2的基本信息,例如: ```xml <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="default" extends="struts-default"> <action name="hello" class="com.example.MyAction"> <result>/index.jsp</result> </action> </package> </struts> ``` 4. 创建Struts2 Action 在`src/main/java`目录下创建一个Java类,例如`MyAction.java`,作为Struts2的Action,例如: ```java package com.example; import com.opensymphony.xwork2.ActionSupport; public class MyAction extends ActionSupport { private String message; public String execute() { message = "Hello, Struts2!"; return SUCCESS; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } } ``` 5. 创建JSP页面 在`src/main/webapp`目录下创建一个JSP页面,例如`index.jsp`,用于显示Action的返回结果: ```html <html> <head> <title>Struts2 Example</title> </head> <body> <h1>${message}</h1> </body> </html> ``` 6. 运行项目 使用以下命令在Tomcat中运行项目: ``` mvn tomcat7:run ``` 然后在浏览器中访问`http://localhost:8080/my-struts2-app/hello`即可看到页面上显示的内容"Hello, Struts2!"。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值