Struts2 无法访问直接通过URL访问jsp文件
来源:互联网 发布:虚拟漫游软件 编辑:程序博客网 时间:2024/05/16 17:09
Struts2 无法访问直接通过URL访问jsp文件
struts2配置文件如下:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts><package name="main" extends="struts-default"><action name="loginPerson"class="com.escape.action.LoginAction"><result name="success">/jsp/welcome.jsp</result><result name="login">/jsp/login.jsp</result></action></package></struts>action类如下:
package com.escape.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {private String username;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}private String password;//编写主方法public String execute(){if("tangbo".equals(username) && "123456".equals(password)){return SUCCESS;//这里直接当成string类型}return LOGIN; }}web.xml如下:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Struts2MVCTest</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <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>*.action</url-pattern> </filter-mapping></web-app>login.jsp文件如下:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'login.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> <s:form action="loginPerson"> <s:label value="login system"></s:label> <br/> <s:textfield name="username" label="username"></s:textfield> <s:textfield name="password" label="password"></s:textfield> <s:submit value="login"></s:submit> </s:form> </body></html>web project的文件目录如下:
浏览器访问jsp文件下的login.jsp发现错误如下:
只有通过http://localhost:8080/Struts2MVCTest/loginPerson.action才能正确访问。
查找原因:直接在jsp文件夹下新建一个jsp通过URL可以直接访问。网上搜索原因,部分人说是因为在jsp中加入了struts2标签库。查看了书的源例程之后看到struts配置如下:
要将login设置成全局result。发现还是不可以,最后再找原因原来是web.xml配置URLpattern时没有配置jsp文件夹,添加如下:
<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>*.action</url-pattern> <url-pattern>/jsp/*</url-pattern> </filter-mapping>然后可以直接通过URL:http://localhost:8080/Struts2MVCTest/jsp/login.jsp直接访问。
排除方法:1.排除web.xml配置问题 2.排除struts2配置问题
0 0
- Struts2 无法访问直接通过URL访问jsp文件
- url直接访问jsp文件
- 禁止通过 url直接访问
- Struts2实现文件上传,直接访问JSP页面出现异常
- struts2使用JSP直接访问国际化资源文件
- WEB-INF下的JSP是不能通过URL直接访问的
- WEB-INF下的JSP是不能通过URL直接访问的
- WEB-INF下的JSP是不能通过URL直接访问的
- struts2下无法用直接通过路径访问.jsp的页面
- 通过struts2的配置文件访问jsp
- 关于JSP不能通过浏览器直接访问,要通过servlet跳转,但一个jsp文件里面用<iframe>标签包含了另一个jsp的访问问题
- 直接通过网页jsp导出Excel文件
- WEB-INF目录防止通过URL直接访问页面
- 网页中怎样禁止通过输入url直接访问
- 网页中怎样禁止通过输入url直接访问
- WEB-INF目录防止通过URL直接访问
- ASP.NET如何禁止直接通过Url访问某个类型的文件(非权限),不定时补充
- SpringMVC restful风格URL不能通过域名访问index.jsp
- 19. Remove Nth Node From End of List
- SaaS营销网站的剖析——SaaS品牌化
- JQ验证插件的使用
- hadoop使用场景
- ClickableSpan 去除下划线
- Struts2 无法访问直接通过URL访问jsp文件
- iOS应用支持IPV6,就那点事儿
- swift获取View所在ViewController的控制器对象
- Android屏幕单位整理:dpi, density...
- 玩转Android之设备方向
- 微信分享完整demo
- 安卓BLE开发个人总结
- iOS扫描二维码方法
- Suricata+PF_RING安装详解